1 #include "threads_impl.h"
2 
pthread_rwlock_tryrdlock(pthread_rwlock_t * rw)3 int pthread_rwlock_tryrdlock(pthread_rwlock_t* rw) {
4     int val, cnt;
5     do {
6         val = atomic_load(&rw->_rw_lock);
7         cnt = val & 0x7fffffff;
8         if (cnt == 0x7fffffff)
9             return EBUSY;
10         if (cnt == 0x7ffffffe)
11             return EAGAIN;
12     } while (a_cas_shim(&rw->_rw_lock, val, val + 1) != val);
13     return 0;
14 }
15