Locking system overhaul, add condition variables
authorPieter Wuille <pieter.wuille@gmail.com>
Mon, 2 Apr 2012 00:40:41 +0000 (02:40 +0200)
committerPieter Wuille <pieter.wuille@gmail.com>
Wed, 4 Apr 2012 14:21:08 +0000 (16:21 +0200)
commit712fd182b72b0f5a1bcf843f171c29ec0a49b50f
treeac5edf9ece53a8f03fde992b0fbfa9a11c8db688
parentb0a7e05a45a925d78efd00ecca6dce9b7a9530f9
Locking system overhaul, add condition variables

This commit simplifies the locking system: CCriticalSection becomes a
simple typedef for boost::interprocess::interprocess_recursive_mutex,
and CCriticalBlock and CTryCriticalBlock are replaced by a templated
CMutexLock, which wraps boost::interprocess::scoped_lock.

By making the lock type a template parameter, some critical sections
can now be changed to non-recursive locks, which support waiting via
condition variables. These are implemented in CWaitableCriticalSection
and WAITABLE_CRITICAL_BLOCK.

CWaitableCriticalSection is a wrapper for a different Boost mutex,
which supports waiting/notification via condition variables. This
should enable us to remove much of the used polling code. Important
is that this mutex is not recursive, so functions that perform the
locking must not call eachother.

Because boost::interprocess::scoped_lock does not support assigning
and copying, I had to revert to the older CRITICAL_BLOCK macros that
use a nested for loop instead of a simple if.
src/util.cpp
src/util.h