diff options
| author | Antoine Riard <[email protected]> | 2019-04-19 07:48:31 -0400 |
|---|---|---|
| committer | Antoine Riard <[email protected]> | 2019-04-20 08:13:34 -0400 |
| commit | edfe9438ca54274815f076fc21beb790df5aa0a2 (patch) | |
| tree | 79201236fc1d8c452a4c3a0ffb6bfe912d6d41a7 /src | |
| parent | Merge #15779: test: Add wallet_balance benchmark (diff) | |
| download | discoin-edfe9438ca54274815f076fc21beb790df5aa0a2.tar.xz discoin-edfe9438ca54274815f076fc21beb790df5aa0a2.zip | |
Add WITH_LOCK macro: run code while locking a mutex
Results from ryanofksy suggestion on isPotentialTip/
waitForNotifications refactoring
Diffstat (limited to 'src')
| -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 3857eda56..2667fb52f 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: |