Lines Matching refs:mutex

145 __gthr_win32_mutex_init_function (__gthread_mutex_t *mutex)  in __gthr_win32_mutex_init_function()  argument
147 mutex->counter = -1; in __gthr_win32_mutex_init_function()
148 mutex->sema = CreateSemaphoreW (NULL, 0, 65535, NULL); in __gthr_win32_mutex_init_function()
152 __gthr_win32_mutex_destroy (__gthread_mutex_t *mutex) in __gthr_win32_mutex_destroy() argument
154 CloseHandle ((HANDLE) mutex->sema); in __gthr_win32_mutex_destroy()
158 __gthr_win32_mutex_lock (__gthread_mutex_t *mutex) in __gthr_win32_mutex_lock() argument
160 if (InterlockedIncrement (&mutex->counter) == 0 || in __gthr_win32_mutex_lock()
161 WaitForSingleObject (mutex->sema, INFINITE) == WAIT_OBJECT_0) in __gthr_win32_mutex_lock()
167 InterlockedDecrement (&mutex->counter); in __gthr_win32_mutex_lock()
173 __gthr_win32_mutex_trylock (__gthread_mutex_t *mutex) in __gthr_win32_mutex_trylock() argument
175 if (__GTHR_W32_InterlockedCompareExchange (&mutex->counter, 0, -1) < 0) in __gthr_win32_mutex_trylock()
182 __gthr_win32_mutex_unlock (__gthread_mutex_t *mutex) in __gthr_win32_mutex_unlock() argument
184 if (InterlockedDecrement (&mutex->counter) >= 0) in __gthr_win32_mutex_unlock()
185 return ReleaseSemaphore (mutex->sema, 1, NULL) ? 0 : 1; in __gthr_win32_mutex_unlock()
191 __gthr_win32_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_init_function() argument
193 mutex->counter = -1; in __gthr_win32_recursive_mutex_init_function()
194 mutex->depth = 0; in __gthr_win32_recursive_mutex_init_function()
195 mutex->owner = 0; in __gthr_win32_recursive_mutex_init_function()
196 mutex->sema = CreateSemaphoreW (NULL, 0, 65535, NULL); in __gthr_win32_recursive_mutex_init_function()
200 __gthr_win32_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_lock() argument
203 if (InterlockedIncrement (&mutex->counter) == 0) in __gthr_win32_recursive_mutex_lock()
205 mutex->depth = 1; in __gthr_win32_recursive_mutex_lock()
206 mutex->owner = me; in __gthr_win32_recursive_mutex_lock()
208 else if (mutex->owner == me) in __gthr_win32_recursive_mutex_lock()
210 InterlockedDecrement (&mutex->counter); in __gthr_win32_recursive_mutex_lock()
211 ++(mutex->depth); in __gthr_win32_recursive_mutex_lock()
213 else if (WaitForSingleObject (mutex->sema, INFINITE) == WAIT_OBJECT_0) in __gthr_win32_recursive_mutex_lock()
215 mutex->depth = 1; in __gthr_win32_recursive_mutex_lock()
216 mutex->owner = me; in __gthr_win32_recursive_mutex_lock()
222 InterlockedDecrement (&mutex->counter); in __gthr_win32_recursive_mutex_lock()
229 __gthr_win32_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_trylock() argument
232 if (__GTHR_W32_InterlockedCompareExchange (&mutex->counter, 0, -1) < 0) in __gthr_win32_recursive_mutex_trylock()
234 mutex->depth = 1; in __gthr_win32_recursive_mutex_trylock()
235 mutex->owner = me; in __gthr_win32_recursive_mutex_trylock()
237 else if (mutex->owner == me) in __gthr_win32_recursive_mutex_trylock()
238 ++(mutex->depth); in __gthr_win32_recursive_mutex_trylock()
246 __gthr_win32_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_unlock() argument
248 --(mutex->depth); in __gthr_win32_recursive_mutex_unlock()
249 if (mutex->depth == 0) in __gthr_win32_recursive_mutex_unlock()
251 mutex->owner = 0; in __gthr_win32_recursive_mutex_unlock()
253 if (InterlockedDecrement (&mutex->counter) >= 0) in __gthr_win32_recursive_mutex_unlock()
254 return ReleaseSemaphore (mutex->sema, 1, NULL) ? 0 : 1; in __gthr_win32_recursive_mutex_unlock()
261 __gthr_win32_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex) in __gthr_win32_recursive_mutex_destroy() argument
263 CloseHandle ((HANDLE) mutex->sema); in __gthr_win32_recursive_mutex_destroy()