Changeset 763
- Timestamp:
- 06/25/08 13:04:13 (2 months ago)
- Files:
-
- trunk/phobos/std/synchro.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/synchro.d
r760 r763 85 85 86 86 /** 87 Implements mutual exclusion. 87 Implements mutual exclusion. $(D Mutex) is re-entrant, i.e., 88 the same thread may lock it multiple times. 89 It must unlock it the same number of times. 88 90 89 91 Note: On Windows, it's implemented as $(D CriticalSection); on Linux, using pthreads. … … 110 112 LeaveCriticalSection (&_critSection); 111 113 } 114 /** 115 Returns $(D true) if lock taken. 116 */ 112 117 bool trylock() 113 118 { … … 127 132 private import std.c.linux.linuxextern; 128 133 134 private pthread_mutexattr_t monitors_attr; 135 136 // Revisit: This should be called before static constructors, in case they start a thread 137 static this() 138 { 139 // Warning: this is non-portable 140 pthread_mutexattr_init(&_monitors_attr); 141 pthread_mutexattr_settype(&_monitors_attr, PTHREAD_MUTEX_RECURSIVE_NP); 142 } 143 144 static ~this() 145 { 146 pthread_mutexattr_destroy(&_monitors_attr); 147 } 148 129 149 class Mutex: Lockable 130 150 { … … 132 152 this() 133 153 { 134 pthread_mutex_init(&_mtx, null);154 pthread_mutex_init(&_mtx, &monitors_attr); 135 155 } 136 156 ~this()
