pthread_rwlock_tryrdlock.c 293 B

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