Lines Matching refs:lock
31 glthread_lock_init (gl_lock_t *lock) in glthread_lock_init() argument
33 if (mtx_init (&lock->mutex, mtx_plain) != thrd_success) in glthread_lock_init()
35 lock->init_needed = 0; in glthread_lock_init()
40 glthread_lock_lock (gl_lock_t *lock) in glthread_lock_lock() argument
42 if (lock->init_needed) in glthread_lock_lock()
43 call_once (&lock->init_once, lock->init_func); in glthread_lock_lock()
44 if (mtx_lock (&lock->mutex) != thrd_success) in glthread_lock_lock()
50 glthread_lock_unlock (gl_lock_t *lock) in glthread_lock_unlock() argument
52 if (lock->init_needed) in glthread_lock_unlock()
53 call_once (&lock->init_once, lock->init_func); in glthread_lock_unlock()
54 if (mtx_unlock (&lock->mutex) != thrd_success) in glthread_lock_unlock()
60 glthread_lock_destroy (gl_lock_t *lock) in glthread_lock_destroy() argument
62 if (lock->init_needed) in glthread_lock_destroy()
63 call_once (&lock->init_once, lock->init_func); in glthread_lock_destroy()
64 mtx_destroy (&lock->mutex); in glthread_lock_destroy()
71 glthread_rwlock_init (gl_rwlock_t *lock) in glthread_rwlock_init() argument
73 if (mtx_init (&lock->lock, mtx_plain) != thrd_success in glthread_rwlock_init()
74 || cnd_init (&lock->waiting_readers) != thrd_success in glthread_rwlock_init()
75 || cnd_init (&lock->waiting_writers) != thrd_success) in glthread_rwlock_init()
77 lock->waiting_writers_count = 0; in glthread_rwlock_init()
78 lock->runcount = 0; in glthread_rwlock_init()
79 lock->init_needed = 0; in glthread_rwlock_init()
84 glthread_rwlock_rdlock (gl_rwlock_t *lock) in glthread_rwlock_rdlock() argument
86 if (lock->init_needed) in glthread_rwlock_rdlock()
87 call_once (&lock->init_once, lock->init_func); in glthread_rwlock_rdlock()
88 if (mtx_lock (&lock->lock) != thrd_success) in glthread_rwlock_rdlock()
94 while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) in glthread_rwlock_rdlock()
98 if (cnd_wait (&lock->waiting_readers, &lock->lock) != thrd_success) in glthread_rwlock_rdlock()
100 mtx_unlock (&lock->lock); in glthread_rwlock_rdlock()
104 lock->runcount++; in glthread_rwlock_rdlock()
105 if (mtx_unlock (&lock->lock) != thrd_success) in glthread_rwlock_rdlock()
111 glthread_rwlock_wrlock (gl_rwlock_t *lock) in glthread_rwlock_wrlock() argument
113 if (lock->init_needed) in glthread_rwlock_wrlock()
114 call_once (&lock->init_once, lock->init_func); in glthread_rwlock_wrlock()
115 if (mtx_lock (&lock->lock) != thrd_success) in glthread_rwlock_wrlock()
118 while (!(lock->runcount == 0)) in glthread_rwlock_wrlock()
122 lock->waiting_writers_count++; in glthread_rwlock_wrlock()
123 if (cnd_wait (&lock->waiting_writers, &lock->lock) != thrd_success) in glthread_rwlock_wrlock()
125 lock->waiting_writers_count--; in glthread_rwlock_wrlock()
126 mtx_unlock (&lock->lock); in glthread_rwlock_wrlock()
129 lock->waiting_writers_count--; in glthread_rwlock_wrlock()
131 lock->runcount--; /* runcount becomes -1 */ in glthread_rwlock_wrlock()
132 if (mtx_unlock (&lock->lock) != thrd_success) in glthread_rwlock_wrlock()
138 glthread_rwlock_unlock (gl_rwlock_t *lock) in glthread_rwlock_unlock() argument
140 if (lock->init_needed) in glthread_rwlock_unlock()
141 call_once (&lock->init_once, lock->init_func); in glthread_rwlock_unlock()
142 if (mtx_lock (&lock->lock) != thrd_success) in glthread_rwlock_unlock()
144 if (lock->runcount < 0) in glthread_rwlock_unlock()
147 if (!(lock->runcount == -1)) in glthread_rwlock_unlock()
149 mtx_unlock (&lock->lock); in glthread_rwlock_unlock()
152 lock->runcount = 0; in glthread_rwlock_unlock()
157 if (!(lock->runcount > 0)) in glthread_rwlock_unlock()
159 mtx_unlock (&lock->lock); in glthread_rwlock_unlock()
162 lock->runcount--; in glthread_rwlock_unlock()
164 if (lock->runcount == 0) in glthread_rwlock_unlock()
168 if (lock->waiting_writers_count > 0) in glthread_rwlock_unlock()
171 if (cnd_signal (&lock->waiting_writers) != thrd_success) in glthread_rwlock_unlock()
173 mtx_unlock (&lock->lock); in glthread_rwlock_unlock()
180 if (cnd_broadcast (&lock->waiting_readers) != thrd_success) in glthread_rwlock_unlock()
182 mtx_unlock (&lock->lock); in glthread_rwlock_unlock()
187 if (mtx_unlock (&lock->lock) != thrd_success) in glthread_rwlock_unlock()
193 glthread_rwlock_destroy (gl_rwlock_t *lock) in glthread_rwlock_destroy() argument
195 if (lock->init_needed) in glthread_rwlock_destroy()
196 call_once (&lock->init_once, lock->init_func); in glthread_rwlock_destroy()
197 mtx_destroy (&lock->lock); in glthread_rwlock_destroy()
198 cnd_destroy (&lock->waiting_readers); in glthread_rwlock_destroy()
199 cnd_destroy (&lock->waiting_writers); in glthread_rwlock_destroy()
206 glthread_recursive_lock_init (gl_recursive_lock_t *lock) in glthread_recursive_lock_init() argument
208 if (mtx_init (&lock->mutex, mtx_plain | mtx_recursive) != thrd_success) in glthread_recursive_lock_init()
210 lock->init_needed = 0; in glthread_recursive_lock_init()
215 glthread_recursive_lock_lock (gl_recursive_lock_t *lock) in glthread_recursive_lock_lock() argument
217 if (lock->init_needed) in glthread_recursive_lock_lock()
218 call_once (&lock->init_once, lock->init_func); in glthread_recursive_lock_lock()
219 if (mtx_lock (&lock->mutex) != thrd_success) in glthread_recursive_lock_lock()
225 glthread_recursive_lock_unlock (gl_recursive_lock_t *lock) in glthread_recursive_lock_unlock() argument
227 if (lock->init_needed) in glthread_recursive_lock_unlock()
228 call_once (&lock->init_once, lock->init_func); in glthread_recursive_lock_unlock()
229 if (mtx_unlock (&lock->mutex) != thrd_success) in glthread_recursive_lock_unlock()
235 glthread_recursive_lock_destroy (gl_recursive_lock_t *lock) in glthread_recursive_lock_destroy() argument
237 if (lock->init_needed) in glthread_recursive_lock_destroy()
238 call_once (&lock->init_once, lock->init_func); in glthread_recursive_lock_destroy()
239 mtx_destroy (&lock->mutex); in glthread_recursive_lock_destroy()
263 glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock) in glthread_rwlock_init_for_glibc() argument
278 err = pthread_rwlock_init(lock, &attributes); in glthread_rwlock_init_for_glibc()
289 glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_init_multithreaded() argument
293 err = pthread_rwlock_init (&lock->rwlock, NULL); in glthread_rwlock_init_multithreaded()
296 lock->initialized = 1; in glthread_rwlock_init_multithreaded()
301 glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_rdlock_multithreaded() argument
303 if (!lock->initialized) in glthread_rwlock_rdlock_multithreaded()
307 err = pthread_mutex_lock (&lock->guard); in glthread_rwlock_rdlock_multithreaded()
310 if (!lock->initialized) in glthread_rwlock_rdlock_multithreaded()
312 err = glthread_rwlock_init_multithreaded (lock); in glthread_rwlock_rdlock_multithreaded()
315 pthread_mutex_unlock (&lock->guard); in glthread_rwlock_rdlock_multithreaded()
319 err = pthread_mutex_unlock (&lock->guard); in glthread_rwlock_rdlock_multithreaded()
323 return pthread_rwlock_rdlock (&lock->rwlock); in glthread_rwlock_rdlock_multithreaded()
327 glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_wrlock_multithreaded() argument
329 if (!lock->initialized) in glthread_rwlock_wrlock_multithreaded()
333 err = pthread_mutex_lock (&lock->guard); in glthread_rwlock_wrlock_multithreaded()
336 if (!lock->initialized) in glthread_rwlock_wrlock_multithreaded()
338 err = glthread_rwlock_init_multithreaded (lock); in glthread_rwlock_wrlock_multithreaded()
341 pthread_mutex_unlock (&lock->guard); in glthread_rwlock_wrlock_multithreaded()
345 err = pthread_mutex_unlock (&lock->guard); in glthread_rwlock_wrlock_multithreaded()
349 return pthread_rwlock_wrlock (&lock->rwlock); in glthread_rwlock_wrlock_multithreaded()
353 glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_unlock_multithreaded() argument
355 if (!lock->initialized) in glthread_rwlock_unlock_multithreaded()
357 return pthread_rwlock_unlock (&lock->rwlock); in glthread_rwlock_unlock_multithreaded()
361 glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_destroy_multithreaded() argument
365 if (!lock->initialized) in glthread_rwlock_destroy_multithreaded()
367 err = pthread_rwlock_destroy (&lock->rwlock); in glthread_rwlock_destroy_multithreaded()
370 lock->initialized = 0; in glthread_rwlock_destroy_multithreaded()
379 glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_init_multithreaded() argument
383 err = pthread_mutex_init (&lock->lock, NULL); in glthread_rwlock_init_multithreaded()
386 err = pthread_cond_init (&lock->waiting_readers, NULL); in glthread_rwlock_init_multithreaded()
389 err = pthread_cond_init (&lock->waiting_writers, NULL); in glthread_rwlock_init_multithreaded()
392 lock->waiting_writers_count = 0; in glthread_rwlock_init_multithreaded()
393 lock->runcount = 0; in glthread_rwlock_init_multithreaded()
398 glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_rdlock_multithreaded() argument
402 err = pthread_mutex_lock (&lock->lock); in glthread_rwlock_rdlock_multithreaded()
409 while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) in glthread_rwlock_rdlock_multithreaded()
413 err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); in glthread_rwlock_rdlock_multithreaded()
416 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_rdlock_multithreaded()
420 lock->runcount++; in glthread_rwlock_rdlock_multithreaded()
421 return pthread_mutex_unlock (&lock->lock); in glthread_rwlock_rdlock_multithreaded()
425 glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_wrlock_multithreaded() argument
429 err = pthread_mutex_lock (&lock->lock); in glthread_rwlock_wrlock_multithreaded()
433 while (!(lock->runcount == 0)) in glthread_rwlock_wrlock_multithreaded()
437 lock->waiting_writers_count++; in glthread_rwlock_wrlock_multithreaded()
438 err = pthread_cond_wait (&lock->waiting_writers, &lock->lock); in glthread_rwlock_wrlock_multithreaded()
441 lock->waiting_writers_count--; in glthread_rwlock_wrlock_multithreaded()
442 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_wrlock_multithreaded()
445 lock->waiting_writers_count--; in glthread_rwlock_wrlock_multithreaded()
447 lock->runcount--; /* runcount becomes -1 */ in glthread_rwlock_wrlock_multithreaded()
448 return pthread_mutex_unlock (&lock->lock); in glthread_rwlock_wrlock_multithreaded()
452 glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_unlock_multithreaded() argument
456 err = pthread_mutex_lock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
459 if (lock->runcount < 0) in glthread_rwlock_unlock_multithreaded()
462 if (!(lock->runcount == -1)) in glthread_rwlock_unlock_multithreaded()
464 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
467 lock->runcount = 0; in glthread_rwlock_unlock_multithreaded()
472 if (!(lock->runcount > 0)) in glthread_rwlock_unlock_multithreaded()
474 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
477 lock->runcount--; in glthread_rwlock_unlock_multithreaded()
479 if (lock->runcount == 0) in glthread_rwlock_unlock_multithreaded()
483 if (lock->waiting_writers_count > 0) in glthread_rwlock_unlock_multithreaded()
486 err = pthread_cond_signal (&lock->waiting_writers); in glthread_rwlock_unlock_multithreaded()
489 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
496 err = pthread_cond_broadcast (&lock->waiting_readers); in glthread_rwlock_unlock_multithreaded()
499 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
504 return pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
508 glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_destroy_multithreaded() argument
512 err = pthread_mutex_destroy (&lock->lock); in glthread_rwlock_destroy_multithreaded()
515 err = pthread_cond_destroy (&lock->waiting_readers); in glthread_rwlock_destroy_multithreaded()
518 err = pthread_cond_destroy (&lock->waiting_writers); in glthread_rwlock_destroy_multithreaded()
533 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_init_multithreaded() argument
547 err = pthread_mutex_init (lock, &attributes); in glthread_recursive_lock_init_multithreaded()
562 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_init_multithreaded() argument
576 err = pthread_mutex_init (&lock->recmutex, &attributes); in glthread_recursive_lock_init_multithreaded()
585 lock->initialized = 1; in glthread_recursive_lock_init_multithreaded()
590 glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_lock_multithreaded() argument
592 if (!lock->initialized) in glthread_recursive_lock_lock_multithreaded()
596 err = pthread_mutex_lock (&lock->guard); in glthread_recursive_lock_lock_multithreaded()
599 if (!lock->initialized) in glthread_recursive_lock_lock_multithreaded()
601 err = glthread_recursive_lock_init_multithreaded (lock); in glthread_recursive_lock_lock_multithreaded()
604 pthread_mutex_unlock (&lock->guard); in glthread_recursive_lock_lock_multithreaded()
608 err = pthread_mutex_unlock (&lock->guard); in glthread_recursive_lock_lock_multithreaded()
612 return pthread_mutex_lock (&lock->recmutex); in glthread_recursive_lock_lock_multithreaded()
616 glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_unlock_multithreaded() argument
618 if (!lock->initialized) in glthread_recursive_lock_unlock_multithreaded()
620 return pthread_mutex_unlock (&lock->recmutex); in glthread_recursive_lock_unlock_multithreaded()
624 glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_destroy_multithreaded() argument
628 if (!lock->initialized) in glthread_recursive_lock_destroy_multithreaded()
630 err = pthread_mutex_destroy (&lock->recmutex); in glthread_recursive_lock_destroy_multithreaded()
633 lock->initialized = 0; in glthread_recursive_lock_destroy_multithreaded()
642 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_init_multithreaded() argument
646 err = pthread_mutex_init (&lock->mutex, NULL); in glthread_recursive_lock_init_multithreaded()
649 lock->owner = (pthread_t) 0; in glthread_recursive_lock_init_multithreaded()
650 lock->depth = 0; in glthread_recursive_lock_init_multithreaded()
655 glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_lock_multithreaded() argument
658 if (lock->owner != self) in glthread_recursive_lock_lock_multithreaded()
662 err = pthread_mutex_lock (&lock->mutex); in glthread_recursive_lock_lock_multithreaded()
665 lock->owner = self; in glthread_recursive_lock_lock_multithreaded()
667 if (++(lock->depth) == 0) /* wraparound? */ in glthread_recursive_lock_lock_multithreaded()
669 lock->depth--; in glthread_recursive_lock_lock_multithreaded()
676 glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_unlock_multithreaded() argument
678 if (lock->owner != pthread_self ()) in glthread_recursive_lock_unlock_multithreaded()
680 if (lock->depth == 0) in glthread_recursive_lock_unlock_multithreaded()
682 if (--(lock->depth) == 0) in glthread_recursive_lock_unlock_multithreaded()
684 lock->owner = (pthread_t) 0; in glthread_recursive_lock_unlock_multithreaded()
685 return pthread_mutex_unlock (&lock->mutex); in glthread_recursive_lock_unlock_multithreaded()
692 glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_destroy_multithreaded() argument
694 if (lock->owner != (pthread_t) 0) in glthread_recursive_lock_destroy_multithreaded()
696 return pthread_mutex_destroy (&lock->mutex); in glthread_recursive_lock_destroy_multithreaded()