Lines Matching refs:mutex
28 glwthread_recmutex_init (glwthread_recmutex_t *mutex)
30 mutex->owner = 0;
31 mutex->depth = 0;
32 InitializeCriticalSection (&mutex->lock);
33 mutex->guard.done = 1;
37 glwthread_recmutex_lock (glwthread_recmutex_t *mutex)
39 if (!mutex->guard.done)
41 if (InterlockedIncrement (&mutex->guard.started) == 0)
42 /* This thread is the first one to need this mutex. Initialize it. */
43 glwthread_recmutex_init (mutex);
46 /* Don't let mutex->guard.started grow and wrap around. */
47 InterlockedDecrement (&mutex->guard.started);
49 initializing this mutex. */
50 while (!mutex->guard.done)
56 if (mutex->owner != self)
58 EnterCriticalSection (&mutex->lock);
59 mutex->owner = self;
61 if (++(mutex->depth) == 0) /* wraparound? */
63 mutex->depth--;
71 glwthread_recmutex_trylock (glwthread_recmutex_t *mutex)
73 if (!mutex->guard.done)
75 if (InterlockedIncrement (&mutex->guard.started) == 0)
76 /* This thread is the first one to need this mutex. Initialize it. */
77 glwthread_recmutex_init (mutex);
80 /* Don't let mutex->guard.started grow and wrap around. */
81 InterlockedDecrement (&mutex->guard.started);
82 /* Let another thread finish initializing this mutex, and let it also
83 lock this mutex. */
89 if (mutex->owner != self)
91 if (!TryEnterCriticalSection (&mutex->lock))
93 mutex->owner = self;
95 if (++(mutex->depth) == 0) /* wraparound? */
97 mutex->depth--;
105 glwthread_recmutex_unlock (glwthread_recmutex_t *mutex)
107 if (mutex->owner != GetCurrentThreadId ())
109 if (mutex->depth == 0)
111 if (--(mutex->depth) == 0)
113 mutex->owner = 0;
114 LeaveCriticalSection (&mutex->lock);
120 glwthread_recmutex_destroy (glwthread_recmutex_t *mutex)
122 if (mutex->owner != 0)
124 DeleteCriticalSection (&mutex->lock);
125 mutex->guard.done = 0;