Lines Matching refs:mutex
147 __gthr_win32_mutex_init_function (__gthread_mutex_t *mutex) in __gthr_win32_mutex_init_function() argument
149 mutex->counter = -1; in __gthr_win32_mutex_init_function()
150 mutex->sema = CreateSemaphoreW (NULL, 0, 65535, NULL); in __gthr_win32_mutex_init_function()
154 __gthr_win32_mutex_destroy (__gthread_mutex_t *mutex) in __gthr_win32_mutex_destroy() argument
156 CloseHandle ((HANDLE) mutex->sema); in __gthr_win32_mutex_destroy()
160 __gthr_win32_mutex_lock (__gthread_mutex_t *mutex) in __gthr_win32_mutex_lock() argument
162 if (InterlockedIncrement (&mutex->counter) == 0 || in __gthr_win32_mutex_lock()
163 WaitForSingleObject (mutex->sema, INFINITE) == WAIT_OBJECT_0) in __gthr_win32_mutex_lock()
169 InterlockedDecrement (&mutex->counter); in __gthr_win32_mutex_lock()
175 __gthr_win32_mutex_trylock (__gthread_mutex_t *mutex) in __gthr_win32_mutex_trylock() argument
177 if (__GTHR_W32_InterlockedCompareExchange (&mutex->counter, 0, -1) < 0) in __gthr_win32_mutex_trylock()
184 __gthr_win32_mutex_unlock (__gthread_mutex_t *mutex) in __gthr_win32_mutex_unlock() argument
186 if (InterlockedDecrement (&mutex->counter) >= 0) in __gthr_win32_mutex_unlock()
187 return ReleaseSemaphore (mutex->sema, 1, NULL) ? 0 : 1; in __gthr_win32_mutex_unlock()
193 __gthr_win32_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_init_function() argument
195 mutex->counter = -1; in __gthr_win32_recursive_mutex_init_function()
196 mutex->depth = 0; in __gthr_win32_recursive_mutex_init_function()
197 mutex->owner = 0; in __gthr_win32_recursive_mutex_init_function()
198 mutex->sema = CreateSemaphoreW (NULL, 0, 65535, NULL); in __gthr_win32_recursive_mutex_init_function()
202 __gthr_win32_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_lock() argument
205 if (InterlockedIncrement (&mutex->counter) == 0) in __gthr_win32_recursive_mutex_lock()
207 mutex->depth = 1; in __gthr_win32_recursive_mutex_lock()
208 mutex->owner = me; in __gthr_win32_recursive_mutex_lock()
210 else if (mutex->owner == me) in __gthr_win32_recursive_mutex_lock()
212 InterlockedDecrement (&mutex->counter); in __gthr_win32_recursive_mutex_lock()
213 ++(mutex->depth); in __gthr_win32_recursive_mutex_lock()
215 else if (WaitForSingleObject (mutex->sema, INFINITE) == WAIT_OBJECT_0) in __gthr_win32_recursive_mutex_lock()
217 mutex->depth = 1; in __gthr_win32_recursive_mutex_lock()
218 mutex->owner = me; in __gthr_win32_recursive_mutex_lock()
224 InterlockedDecrement (&mutex->counter); in __gthr_win32_recursive_mutex_lock()
231 __gthr_win32_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_trylock() argument
234 if (__GTHR_W32_InterlockedCompareExchange (&mutex->counter, 0, -1) < 0) in __gthr_win32_recursive_mutex_trylock()
236 mutex->depth = 1; in __gthr_win32_recursive_mutex_trylock()
237 mutex->owner = me; in __gthr_win32_recursive_mutex_trylock()
239 else if (mutex->owner == me) in __gthr_win32_recursive_mutex_trylock()
240 ++(mutex->depth); in __gthr_win32_recursive_mutex_trylock()
248 __gthr_win32_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_unlock() argument
250 --(mutex->depth); in __gthr_win32_recursive_mutex_unlock()
251 if (mutex->depth == 0) in __gthr_win32_recursive_mutex_unlock()
253 mutex->owner = 0; in __gthr_win32_recursive_mutex_unlock()
255 if (InterlockedDecrement (&mutex->counter) >= 0) in __gthr_win32_recursive_mutex_unlock()
256 return ReleaseSemaphore (mutex->sema, 1, NULL) ? 0 : 1; in __gthr_win32_recursive_mutex_unlock()
263 __gthr_win32_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_destroy() argument
265 CloseHandle ((HANDLE) mutex->sema); in __gthr_win32_recursive_mutex_destroy()