aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAntoine Riard <ariard@student.42.fr>2019-04-19 07:48:31 -0400
committerAntoine Riard <ariard@student.42.fr>2019-04-20 08:13:34 -0400
commitedfe9438ca54274815f076fc21beb790df5aa0a2 (patch)
tree79201236fc1d8c452a4c3a0ffb6bfe912d6d41a7 /src
parentdae72998e8576439254ee497e82e2b9ce4917977 (diff)
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.h10
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: