Skip to content

Commit

Permalink
Add WITH_LOCK macro: run code while locking a mutex
Browse files Browse the repository at this point in the history
Results from ryanofksy suggestion on isPotentialTip/
waitForNotifications refactoring
  • Loading branch information
Antoine Riard authored and cculianu committed Jun 7, 2021
1 parent ad49f4f commit 9151ce2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sync.h
Expand Up @@ -199,6 +199,16 @@ using DebugLock = UniqueLock<typename std::remove_reference<
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:
std::condition_variable condition;
Expand Down

0 comments on commit 9151ce2

Please sign in to comment.