Lines Matching refs:lock

38 glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)  in glthread_rwlock_init_multithreaded()  argument
42 err = pthread_rwlock_init (&lock->rwlock, NULL); in glthread_rwlock_init_multithreaded()
45 lock->initialized = 1; in glthread_rwlock_init_multithreaded()
50 glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_rdlock_multithreaded() argument
52 if (!lock->initialized) in glthread_rwlock_rdlock_multithreaded()
56 err = pthread_mutex_lock (&lock->guard); in glthread_rwlock_rdlock_multithreaded()
59 if (!lock->initialized) in glthread_rwlock_rdlock_multithreaded()
61 err = glthread_rwlock_init_multithreaded (lock); in glthread_rwlock_rdlock_multithreaded()
64 pthread_mutex_unlock (&lock->guard); in glthread_rwlock_rdlock_multithreaded()
68 err = pthread_mutex_unlock (&lock->guard); in glthread_rwlock_rdlock_multithreaded()
72 return pthread_rwlock_rdlock (&lock->rwlock); in glthread_rwlock_rdlock_multithreaded()
76 glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_wrlock_multithreaded() argument
78 if (!lock->initialized) in glthread_rwlock_wrlock_multithreaded()
82 err = pthread_mutex_lock (&lock->guard); in glthread_rwlock_wrlock_multithreaded()
85 if (!lock->initialized) in glthread_rwlock_wrlock_multithreaded()
87 err = glthread_rwlock_init_multithreaded (lock); in glthread_rwlock_wrlock_multithreaded()
90 pthread_mutex_unlock (&lock->guard); in glthread_rwlock_wrlock_multithreaded()
94 err = pthread_mutex_unlock (&lock->guard); in glthread_rwlock_wrlock_multithreaded()
98 return pthread_rwlock_wrlock (&lock->rwlock); in glthread_rwlock_wrlock_multithreaded()
102 glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_unlock_multithreaded() argument
104 if (!lock->initialized) in glthread_rwlock_unlock_multithreaded()
106 return pthread_rwlock_unlock (&lock->rwlock); in glthread_rwlock_unlock_multithreaded()
110 glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_destroy_multithreaded() argument
114 if (!lock->initialized) in glthread_rwlock_destroy_multithreaded()
116 err = pthread_rwlock_destroy (&lock->rwlock); in glthread_rwlock_destroy_multithreaded()
119 lock->initialized = 0; in glthread_rwlock_destroy_multithreaded()
128 glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_init_multithreaded() argument
132 err = pthread_mutex_init (&lock->lock, NULL); in glthread_rwlock_init_multithreaded()
135 err = pthread_cond_init (&lock->waiting_readers, NULL); in glthread_rwlock_init_multithreaded()
138 err = pthread_cond_init (&lock->waiting_writers, NULL); in glthread_rwlock_init_multithreaded()
141 lock->waiting_writers_count = 0; in glthread_rwlock_init_multithreaded()
142 lock->runcount = 0; in glthread_rwlock_init_multithreaded()
147 glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_rdlock_multithreaded() argument
151 err = pthread_mutex_lock (&lock->lock); in glthread_rwlock_rdlock_multithreaded()
160 while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) in glthread_rwlock_rdlock_multithreaded()
164 err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); in glthread_rwlock_rdlock_multithreaded()
167 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_rdlock_multithreaded()
171 lock->runcount++; in glthread_rwlock_rdlock_multithreaded()
172 return pthread_mutex_unlock (&lock->lock); in glthread_rwlock_rdlock_multithreaded()
176 glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_wrlock_multithreaded() argument
180 err = pthread_mutex_lock (&lock->lock); in glthread_rwlock_wrlock_multithreaded()
184 while (!(lock->runcount == 0)) in glthread_rwlock_wrlock_multithreaded()
188 lock->waiting_writers_count++; in glthread_rwlock_wrlock_multithreaded()
189 err = pthread_cond_wait (&lock->waiting_writers, &lock->lock); in glthread_rwlock_wrlock_multithreaded()
192 lock->waiting_writers_count--; in glthread_rwlock_wrlock_multithreaded()
193 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_wrlock_multithreaded()
196 lock->waiting_writers_count--; in glthread_rwlock_wrlock_multithreaded()
198 lock->runcount--; /* runcount becomes -1 */ in glthread_rwlock_wrlock_multithreaded()
199 return pthread_mutex_unlock (&lock->lock); in glthread_rwlock_wrlock_multithreaded()
203 glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_unlock_multithreaded() argument
207 err = pthread_mutex_lock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
210 if (lock->runcount < 0) in glthread_rwlock_unlock_multithreaded()
213 if (!(lock->runcount == -1)) in glthread_rwlock_unlock_multithreaded()
215 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
218 lock->runcount = 0; in glthread_rwlock_unlock_multithreaded()
223 if (!(lock->runcount > 0)) in glthread_rwlock_unlock_multithreaded()
225 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
228 lock->runcount--; in glthread_rwlock_unlock_multithreaded()
230 if (lock->runcount == 0) in glthread_rwlock_unlock_multithreaded()
234 if (lock->waiting_writers_count > 0) in glthread_rwlock_unlock_multithreaded()
237 err = pthread_cond_signal (&lock->waiting_writers); in glthread_rwlock_unlock_multithreaded()
240 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
247 err = pthread_cond_broadcast (&lock->waiting_readers); in glthread_rwlock_unlock_multithreaded()
250 pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
255 return pthread_mutex_unlock (&lock->lock); in glthread_rwlock_unlock_multithreaded()
259 glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) in glthread_rwlock_destroy_multithreaded() argument
263 err = pthread_mutex_destroy (&lock->lock); in glthread_rwlock_destroy_multithreaded()
266 err = pthread_cond_destroy (&lock->waiting_readers); in glthread_rwlock_destroy_multithreaded()
269 err = pthread_cond_destroy (&lock->waiting_writers); in glthread_rwlock_destroy_multithreaded()
284 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_init_multithreaded() argument
298 err = pthread_mutex_init (lock, &attributes); in glthread_recursive_lock_init_multithreaded()
313 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_init_multithreaded() argument
327 err = pthread_mutex_init (&lock->recmutex, &attributes); in glthread_recursive_lock_init_multithreaded()
336 lock->initialized = 1; in glthread_recursive_lock_init_multithreaded()
341 glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_lock_multithreaded() argument
343 if (!lock->initialized) in glthread_recursive_lock_lock_multithreaded()
347 err = pthread_mutex_lock (&lock->guard); in glthread_recursive_lock_lock_multithreaded()
350 if (!lock->initialized) in glthread_recursive_lock_lock_multithreaded()
352 err = glthread_recursive_lock_init_multithreaded (lock); in glthread_recursive_lock_lock_multithreaded()
355 pthread_mutex_unlock (&lock->guard); in glthread_recursive_lock_lock_multithreaded()
359 err = pthread_mutex_unlock (&lock->guard); in glthread_recursive_lock_lock_multithreaded()
363 return pthread_mutex_lock (&lock->recmutex); in glthread_recursive_lock_lock_multithreaded()
367 glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_unlock_multithreaded() argument
369 if (!lock->initialized) in glthread_recursive_lock_unlock_multithreaded()
371 return pthread_mutex_unlock (&lock->recmutex); in glthread_recursive_lock_unlock_multithreaded()
375 glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_destroy_multithreaded() argument
379 if (!lock->initialized) in glthread_recursive_lock_destroy_multithreaded()
381 err = pthread_mutex_destroy (&lock->recmutex); in glthread_recursive_lock_destroy_multithreaded()
384 lock->initialized = 0; in glthread_recursive_lock_destroy_multithreaded()
393 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_init_multithreaded() argument
397 err = pthread_mutex_init (&lock->mutex, NULL); in glthread_recursive_lock_init_multithreaded()
400 lock->owner = (pthread_t) 0; in glthread_recursive_lock_init_multithreaded()
401 lock->depth = 0; in glthread_recursive_lock_init_multithreaded()
406 glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_lock_multithreaded() argument
409 if (lock->owner != self) in glthread_recursive_lock_lock_multithreaded()
413 err = pthread_mutex_lock (&lock->mutex); in glthread_recursive_lock_lock_multithreaded()
416 lock->owner = self; in glthread_recursive_lock_lock_multithreaded()
418 if (++(lock->depth) == 0) /* wraparound? */ in glthread_recursive_lock_lock_multithreaded()
420 lock->depth--; in glthread_recursive_lock_lock_multithreaded()
427 glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_unlock_multithreaded() argument
429 if (lock->owner != pthread_self ()) in glthread_recursive_lock_unlock_multithreaded()
431 if (lock->depth == 0) in glthread_recursive_lock_unlock_multithreaded()
433 if (--(lock->depth) == 0) in glthread_recursive_lock_unlock_multithreaded()
435 lock->owner = (pthread_t) 0; in glthread_recursive_lock_unlock_multithreaded()
436 return pthread_mutex_unlock (&lock->mutex); in glthread_recursive_lock_unlock_multithreaded()
443 glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_destroy_multithreaded() argument
445 if (lock->owner != (pthread_t) 0) in glthread_recursive_lock_destroy_multithreaded()
447 return pthread_mutex_destroy (&lock->mutex); in glthread_recursive_lock_destroy_multithreaded()
532 glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_init_multithreaded() argument
536 err = mutex_init (&lock->mutex, USYNC_THREAD, NULL); in glthread_recursive_lock_init_multithreaded()
539 lock->owner = (thread_t) 0; in glthread_recursive_lock_init_multithreaded()
540 lock->depth = 0; in glthread_recursive_lock_init_multithreaded()
545 glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_lock_multithreaded() argument
548 if (lock->owner != self) in glthread_recursive_lock_lock_multithreaded()
552 err = mutex_lock (&lock->mutex); in glthread_recursive_lock_lock_multithreaded()
555 lock->owner = self; in glthread_recursive_lock_lock_multithreaded()
557 if (++(lock->depth) == 0) /* wraparound? */ in glthread_recursive_lock_lock_multithreaded()
559 lock->depth--; in glthread_recursive_lock_lock_multithreaded()
566 glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_unlock_multithreaded() argument
568 if (lock->owner != thr_self ()) in glthread_recursive_lock_unlock_multithreaded()
570 if (lock->depth == 0) in glthread_recursive_lock_unlock_multithreaded()
572 if (--(lock->depth) == 0) in glthread_recursive_lock_unlock_multithreaded()
574 lock->owner = (thread_t) 0; in glthread_recursive_lock_unlock_multithreaded()
575 return mutex_unlock (&lock->mutex); in glthread_recursive_lock_unlock_multithreaded()
582 glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) in glthread_recursive_lock_destroy_multithreaded() argument
584 if (lock->owner != (thread_t) 0) in glthread_recursive_lock_destroy_multithreaded()
586 return mutex_destroy (&lock->mutex); in glthread_recursive_lock_destroy_multithreaded()
637 glthread_lock_init_func (gl_lock_t *lock) in glthread_lock_init_func() argument
639 InitializeCriticalSection (&lock->lock); in glthread_lock_init_func()
640 lock->guard.done = 1; in glthread_lock_init_func()
644 glthread_lock_lock_func (gl_lock_t *lock) in glthread_lock_lock_func() argument
646 if (!lock->guard.done) in glthread_lock_lock_func()
648 if (InterlockedIncrement (&lock->guard.started) == 0) in glthread_lock_lock_func()
650 glthread_lock_init (lock); in glthread_lock_lock_func()
654 while (!lock->guard.done) in glthread_lock_lock_func()
657 EnterCriticalSection (&lock->lock); in glthread_lock_lock_func()
662 glthread_lock_unlock_func (gl_lock_t *lock) in glthread_lock_unlock_func() argument
664 if (!lock->guard.done) in glthread_lock_unlock_func()
666 LeaveCriticalSection (&lock->lock); in glthread_lock_unlock_func()
671 glthread_lock_destroy_func (gl_lock_t *lock) in glthread_lock_destroy_func() argument
673 if (!lock->guard.done) in glthread_lock_destroy_func()
675 DeleteCriticalSection (&lock->lock); in glthread_lock_destroy_func()
676 lock->guard.done = 0; in glthread_lock_destroy_func()
774 glthread_rwlock_init_func (gl_rwlock_t *lock) in glthread_rwlock_init_func() argument
776 InitializeCriticalSection (&lock->lock); in glthread_rwlock_init_func()
777 gl_waitqueue_init (&lock->waiting_readers); in glthread_rwlock_init_func()
778 gl_waitqueue_init (&lock->waiting_writers); in glthread_rwlock_init_func()
779 lock->runcount = 0; in glthread_rwlock_init_func()
780 lock->guard.done = 1; in glthread_rwlock_init_func()
784 glthread_rwlock_rdlock_func (gl_rwlock_t *lock) in glthread_rwlock_rdlock_func() argument
786 if (!lock->guard.done) in glthread_rwlock_rdlock_func()
788 if (InterlockedIncrement (&lock->guard.started) == 0) in glthread_rwlock_rdlock_func()
790 glthread_rwlock_init (lock); in glthread_rwlock_rdlock_func()
794 while (!lock->guard.done) in glthread_rwlock_rdlock_func()
797 EnterCriticalSection (&lock->lock); in glthread_rwlock_rdlock_func()
800 if (!(lock->runcount + 1 > 0)) in glthread_rwlock_rdlock_func()
804 HANDLE event = gl_waitqueue_add (&lock->waiting_readers); in glthread_rwlock_rdlock_func()
808 LeaveCriticalSection (&lock->lock); in glthread_rwlock_rdlock_func()
816 if (!(lock->runcount > 0)) in glthread_rwlock_rdlock_func()
825 LeaveCriticalSection (&lock->lock); in glthread_rwlock_rdlock_func()
827 EnterCriticalSection (&lock->lock); in glthread_rwlock_rdlock_func()
829 while (!(lock->runcount + 1 > 0)); in glthread_rwlock_rdlock_func()
832 lock->runcount++; in glthread_rwlock_rdlock_func()
833 LeaveCriticalSection (&lock->lock); in glthread_rwlock_rdlock_func()
838 glthread_rwlock_wrlock_func (gl_rwlock_t *lock) in glthread_rwlock_wrlock_func() argument
840 if (!lock->guard.done) in glthread_rwlock_wrlock_func()
842 if (InterlockedIncrement (&lock->guard.started) == 0) in glthread_rwlock_wrlock_func()
844 glthread_rwlock_init (lock); in glthread_rwlock_wrlock_func()
848 while (!lock->guard.done) in glthread_rwlock_wrlock_func()
851 EnterCriticalSection (&lock->lock); in glthread_rwlock_wrlock_func()
853 if (!(lock->runcount == 0)) in glthread_rwlock_wrlock_func()
857 HANDLE event = gl_waitqueue_add (&lock->waiting_writers); in glthread_rwlock_wrlock_func()
861 LeaveCriticalSection (&lock->lock); in glthread_rwlock_wrlock_func()
869 if (!(lock->runcount == -1)) in glthread_rwlock_wrlock_func()
878 LeaveCriticalSection (&lock->lock); in glthread_rwlock_wrlock_func()
880 EnterCriticalSection (&lock->lock); in glthread_rwlock_wrlock_func()
882 while (!(lock->runcount == 0)); in glthread_rwlock_wrlock_func()
885 lock->runcount--; /* runcount becomes -1 */ in glthread_rwlock_wrlock_func()
886 LeaveCriticalSection (&lock->lock); in glthread_rwlock_wrlock_func()
891 glthread_rwlock_unlock_func (gl_rwlock_t *lock) in glthread_rwlock_unlock_func() argument
893 if (!lock->guard.done) in glthread_rwlock_unlock_func()
895 EnterCriticalSection (&lock->lock); in glthread_rwlock_unlock_func()
896 if (lock->runcount < 0) in glthread_rwlock_unlock_func()
899 if (!(lock->runcount == -1)) in glthread_rwlock_unlock_func()
901 lock->runcount = 0; in glthread_rwlock_unlock_func()
906 if (!(lock->runcount > 0)) in glthread_rwlock_unlock_func()
908 LeaveCriticalSection (&lock->lock); in glthread_rwlock_unlock_func()
911 lock->runcount--; in glthread_rwlock_unlock_func()
913 if (lock->runcount == 0) in glthread_rwlock_unlock_func()
917 if (lock->waiting_writers.count > 0) in glthread_rwlock_unlock_func()
920 lock->runcount--; in glthread_rwlock_unlock_func()
921 gl_waitqueue_notify_first (&lock->waiting_writers); in glthread_rwlock_unlock_func()
926 lock->runcount += lock->waiting_readers.count; in glthread_rwlock_unlock_func()
927 gl_waitqueue_notify_all (&lock->waiting_readers); in glthread_rwlock_unlock_func()
930 LeaveCriticalSection (&lock->lock); in glthread_rwlock_unlock_func()
935 glthread_rwlock_destroy_func (gl_rwlock_t *lock) in glthread_rwlock_destroy_func() argument
937 if (!lock->guard.done) in glthread_rwlock_destroy_func()
939 if (lock->runcount != 0) in glthread_rwlock_destroy_func()
941 DeleteCriticalSection (&lock->lock); in glthread_rwlock_destroy_func()
942 if (lock->waiting_readers.array != NULL) in glthread_rwlock_destroy_func()
943 free (lock->waiting_readers.array); in glthread_rwlock_destroy_func()
944 if (lock->waiting_writers.array != NULL) in glthread_rwlock_destroy_func()
945 free (lock->waiting_writers.array); in glthread_rwlock_destroy_func()
946 lock->guard.done = 0; in glthread_rwlock_destroy_func()
953 glthread_recursive_lock_init_func (gl_recursive_lock_t *lock) in glthread_recursive_lock_init_func() argument
955 lock->owner = 0; in glthread_recursive_lock_init_func()
956 lock->depth = 0; in glthread_recursive_lock_init_func()
957 InitializeCriticalSection (&lock->lock); in glthread_recursive_lock_init_func()
958 lock->guard.done = 1; in glthread_recursive_lock_init_func()
962 glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock) in glthread_recursive_lock_lock_func() argument
964 if (!lock->guard.done) in glthread_recursive_lock_lock_func()
966 if (InterlockedIncrement (&lock->guard.started) == 0) in glthread_recursive_lock_lock_func()
968 glthread_recursive_lock_init (lock); in glthread_recursive_lock_lock_func()
972 while (!lock->guard.done) in glthread_recursive_lock_lock_func()
977 if (lock->owner != self) in glthread_recursive_lock_lock_func()
979 EnterCriticalSection (&lock->lock); in glthread_recursive_lock_lock_func()
980 lock->owner = self; in glthread_recursive_lock_lock_func()
982 if (++(lock->depth) == 0) /* wraparound? */ in glthread_recursive_lock_lock_func()
984 lock->depth--; in glthread_recursive_lock_lock_func()
992 glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock) in glthread_recursive_lock_unlock_func() argument
994 if (lock->owner != GetCurrentThreadId ()) in glthread_recursive_lock_unlock_func()
996 if (lock->depth == 0) in glthread_recursive_lock_unlock_func()
998 if (--(lock->depth) == 0) in glthread_recursive_lock_unlock_func()
1000 lock->owner = 0; in glthread_recursive_lock_unlock_func()
1001 LeaveCriticalSection (&lock->lock); in glthread_recursive_lock_unlock_func()
1007 glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock) in glthread_recursive_lock_destroy_func() argument
1009 if (lock->owner != 0) in glthread_recursive_lock_destroy_func()
1011 DeleteCriticalSection (&lock->lock); in glthread_recursive_lock_destroy_func()
1012 lock->guard.done = 0; in glthread_recursive_lock_destroy_func()
1026 InitializeCriticalSection (&once_control->lock); in glthread_once_func()
1027 EnterCriticalSection (&once_control->lock); in glthread_once_func()
1031 LeaveCriticalSection (&once_control->lock); in glthread_once_func()
1046 EnterCriticalSection (&once_control->lock); in glthread_once_func()
1047 LeaveCriticalSection (&once_control->lock); in glthread_once_func()