Skip to content

Commit edfe943

Browse files
author
Antoine Riard
committed
Add WITH_LOCK macro: run code while locking a mutex
Results from ryanofksy suggestion on isPotentialTip/ waitForNotifications refactoring
1 parent dae7299 commit edfe943

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/sync.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ using DebugLock = UniqueLock<typename std::remove_reference<typename std::remove
198198
LeaveCritical(); \
199199
}
200200

201+
//! Run code while locking a mutex.
202+
//!
203+
//! Examples:
204+
//!
205+
//! WITH_LOCK(cs, shared_val = shared_val + 1);
206+
//!
207+
//! int val = WITH_LOCK(cs, return shared_val);
208+
//!
209+
#define WITH_LOCK(cs, code) [&] { LOCK(cs); code; }()
210+
201211
class CSemaphore
202212
{
203213
private:

0 commit comments

Comments
 (0)