Lines Matching refs:mutex
23 #include "windows-mutex.h"
28 glwthread_mutex_init (glwthread_mutex_t *mutex)
30 InitializeCriticalSection (&mutex->lock);
31 mutex->guard.done = 1;
35 glwthread_mutex_lock (glwthread_mutex_t *mutex)
37 if (!mutex->guard.done)
39 if (InterlockedIncrement (&mutex->guard.started) == 0)
40 /* This thread is the first one to need this mutex. Initialize it. */
41 glwthread_mutex_init (mutex);
44 /* Don't let mutex->guard.started grow and wrap around. */
45 InterlockedDecrement (&mutex->guard.started);
47 initializing this mutex. */
48 while (!mutex->guard.done)
52 EnterCriticalSection (&mutex->lock);
57 glwthread_mutex_trylock (glwthread_mutex_t *mutex)
59 if (!mutex->guard.done)
61 if (InterlockedIncrement (&mutex->guard.started) == 0)
62 /* This thread is the first one to need this mutex. Initialize it. */
63 glwthread_mutex_init (mutex);
66 /* Don't let mutex->guard.started grow and wrap around. */
67 InterlockedDecrement (&mutex->guard.started);
68 /* Let another thread finish initializing this mutex, and let it also
69 lock this mutex. */
73 if (!TryEnterCriticalSection (&mutex->lock))
79 glwthread_mutex_unlock (glwthread_mutex_t *mutex)
81 if (!mutex->guard.done)
83 LeaveCriticalSection (&mutex->lock);
88 glwthread_mutex_destroy (glwthread_mutex_t *mutex)
90 if (!mutex->guard.done)
92 DeleteCriticalSection (&mutex->lock);
93 mutex->guard.done = 0;