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
  • Loading branch information
yurykk committed Jun 17, 2020
1 parent 6e519ba commit e9be861
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/sync.h
Expand Up @@ -190,6 +190,16 @@ class SCOPED_LOCKABLE CCriticalBlock
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:
Expand Down

0 comments on commit e9be861

Please sign in to comment.