PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/synch/mutex.d

http://github.com/wilkie/djehuty
D | 46 lines | 29 code | 13 blank | 4 comment | 0 complexity | a28b27b0487b0ce5d360b83d4a5355ad MD5 | raw file
 1module synch.mutex;
 2
 3import platform.vars.mutex;
 4
 5import synch.condition;
 6
 7import scaffold.thread;
 8
 9// Section: Core/Synchronization
10
11// 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.
12class Mutex {
13	this() {
14		MutexInit(_pfvars);
15	}
16
17	~this() {
18		MutexUninit(_pfvars);
19	}
20
21	// Description: This function will lock the mutex.  This could be used to enter a critical section.
22	void lock() {
23		MutexLock(_pfvars);
24	}
25
26	// Description: This function will unlock a locked mutex.  This could be used to leave a critical section.
27	void unlock() {
28		MutexUnlock(_pfvars);
29	}
30
31	void lock(uint milliseconds) {
32		MutexLock(_pfvars, milliseconds);
33	}
34
35	void wait(Condition cond) {
36		cond.wait(_pfvars);
37	}
38
39	void wait(Waitable forObject) {
40		wait(forObject.waitCondition());
41	}
42
43protected:
44
45	MutexPlatformVars _pfvars;
46}