/synch/mutex.d
http://github.com/wilkie/djehuty · D · 46 lines · 29 code · 13 blank · 4 comment · 0 complexity · a28b27b0487b0ce5d360b83d4a5355ad MD5 · raw file
- module synch.mutex;
- import platform.vars.mutex;
- import synch.condition;
- import scaffold.thread;
- // Section: Core/Synchronization
- // Description: This class provides a simple mutex, also known as a binary semaphore. This is provided as a means to manually lock critical sections. It is initially unlocked.
- class Mutex {
- this() {
- MutexInit(_pfvars);
- }
- ~this() {
- MutexUninit(_pfvars);
- }
- // Description: This function will lock the mutex. This could be used to enter a critical section.
- void lock() {
- MutexLock(_pfvars);
- }
- // Description: This function will unlock a locked mutex. This could be used to leave a critical section.
- void unlock() {
- MutexUnlock(_pfvars);
- }
- void lock(uint milliseconds) {
- MutexLock(_pfvars, milliseconds);
- }
- void wait(Condition cond) {
- cond.wait(_pfvars);
- }
- void wait(Waitable forObject) {
- wait(forObject.waitCondition());
- }
- protected:
- MutexPlatformVars _pfvars;
- }