Page MenuHomePhabricator

sync: detect double lock from the same thread
ClosedPublic

Authored by PiRK on Aug 21 2023, 07:30.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCa9803b74b018: sync: detect double lock from the same thread
Summary

sync: make EnterCritical() & push_lock() type safe

The functions EnterCritical() and push_lock() take a pointer to a
mutex, but that pointer used to be of type void* because we use a few
different types for mutexes. This void* argument was not type safe
because somebody could have send a pointer to anything that is not a
mutex. Furthermore it wouldn't allow to check whether the passed mutex
is recursive or not.

Thus, change the functions to templated ones so that we can implement
stricter checks for non-recursive mutexes. This also simplifies the
callers of EnterCritical().

sync: detect double lock from the same thread

Double lock of the same (non-recursive) mutex from the same thread
is producing an undefined behavior. Detect this from DEBUG_LOCKORDER
and react similarly to the deadlock detection.

This is a backport of core#19337 and core#20507

Note that boost::mutex is no longer in use since D13966

Test Plan
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Aug 21 2023, 07:30
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/test/sync_tests.cpp
63 ↗(On Diff #41864)

Macro likestamp:

This revision is now accepted and ready to land.Aug 21 2023, 08:24