diff options
author | Antoine Riard <ariard@student.42.fr> | 2019-04-19 07:48:31 -0400 |
---|---|---|
committer | Antoine Riard <ariard@student.42.fr> | 2019-04-20 08:13:34 -0400 |
commit | edfe9438ca54274815f076fc21beb790df5aa0a2 (patch) | |
tree | 79201236fc1d8c452a4c3a0ffb6bfe912d6d41a7 | |
parent | dae72998e8576439254ee497e82e2b9ce4917977 (diff) | |
download | bitcoin-edfe9438ca54274815f076fc21beb790df5aa0a2.tar.xz |
Add WITH_LOCK macro: run code while locking a mutex
Results from ryanofksy suggestion on isPotentialTip/
waitForNotifications refactoring
-rw-r--r-- | src/sync.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/sync.h b/src/sync.h index 3857eda56b..2667fb52f9 100644 --- a/src/sync.h +++ b/src/sync.h @@ -198,6 +198,16 @@ using DebugLock = UniqueLock<typename std::remove_reference<typename std::remove LeaveCritical(); \ } +//! Run code while locking a mutex. +//! +//! Examples: +//! +//! WITH_LOCK(cs, shared_val = shared_val + 1); +//! +//! int val = WITH_LOCK(cs, return shared_val); +//! +#define WITH_LOCK(cs, code) [&] { LOCK(cs); code; }() + class CSemaphore { private: |