mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Add WITH_LOCK macro: run code while locking a mutex
Results from ryanofksy suggestion on isPotentialTip/ waitForNotifications refactoring
This commit is contained in:
parent
dae72998e8
commit
edfe9438ca
1 changed files with 10 additions and 0 deletions
10
src/sync.h
10
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue