bitcoin/bitcoin — pull request #3329 by gavinandresen (2013-11-29 07:59:49+00:00)
Title: mutex debugging routines: LocksHeld() and AssertLockHeld()

Inspired by a Mike Hearn comment on #3276 -- adds a couple of mutex-related routines:

AssertLockHeld("cs_foo") : if compiled -DDEBUG_LOCKORDER, walks the lock stack and makes sure the specified lock is held. If not, a message and the list of locks that ARE held are LogPrintf'ed and then assert(0) is called. Does nothing in normal builds.

LocksHeld() : -DDEBUG_LOCKORDER-only routine: returns a human-readable string with all of the locks held. This can be very handy to call from within an interactive debugging session (and it is used by AssertLockHeld).

I added AssertLockHeld("cs_main") to ProcessBlock as proof-of-concept; if we like this, adding AssertLockHeld calls to more routines can be done in subsequent pulls.