Changeset View
Changeset View
Standalone View
Standalone View
src/sync.h
Show First 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | #define ENTER_CRITICAL_SECTION(cs) \ | ||||
} | } | ||||
#define LEAVE_CRITICAL_SECTION(cs) \ | #define LEAVE_CRITICAL_SECTION(cs) \ | ||||
{ \ | { \ | ||||
(cs).unlock(); \ | (cs).unlock(); \ | ||||
LeaveCritical(); \ | 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 { | class CSemaphore { | ||||
private: | private: | ||||
std::condition_variable condition; | std::condition_variable condition; | ||||
std::mutex mutex; | std::mutex mutex; | ||||
int value; | int value; | ||||
public: | public: | ||||
explicit CSemaphore(int init) : value(init) {} | explicit CSemaphore(int init) : value(init) {} | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |