Add WITH_LOCK macro: run code while locking a mutex

Results from ryanofksy suggestion on isPotentialTip/
waitForNotifications refactoring
This commit is contained in:
Antoine Riard 2019-04-19 07:48:31 -04:00
parent dae72998e8
commit edfe9438ca

View file

@ -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: