123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #include <errno.h>
- #include <sysdep.h>
- #include <lowlevellock.h>
- #include <pthread.h>
- #include <pthreadP.h>
- int
- attribute_protected
- __pthread_rwlock_rdlock (
- pthread_rwlock_t *rwlock)
- {
- int result = 0;
-
- lll_lock (rwlock->__data.__lock, rwlock->__data.__shared);
- while (1)
- {
-
- if (rwlock->__data.__writer == 0
-
- && (!rwlock->__data.__nr_writers_queued
- || PTHREAD_RWLOCK_PREFER_READER_P (rwlock)))
- {
-
- if (__builtin_expect (++rwlock->__data.__nr_readers == 0, 0))
- {
-
- --rwlock->__data.__nr_readers;
- result = EAGAIN;
- }
- break;
- }
-
- if (__builtin_expect (rwlock->__data.__writer
- == THREAD_GETMEM (THREAD_SELF, tid), 0))
- {
- result = EDEADLK;
- break;
- }
-
- if (__builtin_expect (++rwlock->__data.__nr_readers_queued == 0, 0))
- {
-
- --rwlock->__data.__nr_readers_queued;
- result = EAGAIN;
- break;
- }
- int waitval = rwlock->__data.__readers_wakeup;
-
- lll_unlock (rwlock->__data.__lock, rwlock->__data.__shared);
-
- lll_futex_wait (&rwlock->__data.__readers_wakeup, waitval,
- rwlock->__data.__shared);
-
- lll_lock (rwlock->__data.__lock, rwlock->__data.__shared);
- --rwlock->__data.__nr_readers_queued;
- }
-
- lll_unlock (rwlock->__data.__lock, rwlock->__data.__shared);
- return result;
- }
- weak_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock)
- strong_alias (__pthread_rwlock_rdlock, __pthread_rwlock_rdlock_internal)
|