6 #ifndef ICE_UTIL_MUTEX_H
7 #define ICE_UTIL_MUTEX_H
69 bool willUnlock()
const;
76 void operator=(
const Mutex&);
85 # ifdef ICE_HAS_WIN32_CONDVAR
86 CRITICAL_SECTION* mutex;
92 pthread_mutex_t* mutex;
96 void unlock(LockState&)
const;
97 void lock(LockState&)
const;
102 mutable CRITICAL_SECTION _mutex;
104 mutable pthread_mutex_t _mutex;
140 InitializeCriticalSection(&_mutex);
146 DeleteCriticalSection(&_mutex);
152 EnterCriticalSection(&_mutex);
154 if(_mutex.RecursionCount > 1)
156 LeaveCriticalSection(&_mutex);
157 throw ThreadLockedException(__FILE__, __LINE__);
165 if(!TryEnterCriticalSection(&_mutex))
169 if(_mutex.RecursionCount > 1)
171 LeaveCriticalSection(&_mutex);
172 throw ThreadLockedException(__FILE__, __LINE__);
180 assert(_mutex.RecursionCount == 1);
181 LeaveCriticalSection(&_mutex);
184 # ifdef ICE_HAS_WIN32_CONDVAR
188 state.mutex = &_mutex;
199 LeaveCriticalSection(&_mutex);
205 EnterCriticalSection(&_mutex);
213 #
if defined(_POSIX_THREAD_PRIO_INHERIT) && _POSIX_THREAD_PRIO_INHERIT > 0
219 pthread_mutexattr_t attr;
220 rc = pthread_mutexattr_init(&attr);
224 pthread_mutexattr_destroy(&attr);
225 throw ThreadSyscallException(__FILE__, __LINE__, rc);
231 rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
235 pthread_mutexattr_destroy(&attr);
236 throw ThreadSyscallException(__FILE__, __LINE__, rc);
243 #if defined(_POSIX_THREAD_PRIO_INHERIT) && _POSIX_THREAD_PRIO_INHERIT > 0
246 rc = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
249 pthread_mutexattr_destroy(&attr);
250 throw ThreadSyscallException(__FILE__, __LINE__, rc);
255 rc = pthread_mutex_init(&_mutex, &attr);
259 pthread_mutexattr_destroy(&attr);
260 throw ThreadSyscallException(__FILE__, __LINE__, rc);
263 rc = pthread_mutexattr_destroy(&attr);
267 throw ThreadSyscallException(__FILE__, __LINE__, rc);
276 rc = pthread_mutex_destroy(&_mutex);
279 pthread_mutex_destroy(&_mutex);
286 int rc = pthread_mutex_lock(&_mutex);
303 int rc = pthread_mutex_trylock(&_mutex);
304 if(rc != 0 && rc != EBUSY)
321 int rc = pthread_mutex_unlock(&_mutex);
331 state.mutex = &_mutex;