minor locking optimizations
[musl] / src / thread / pthread_rwlock_unlock.c
1 #include "pthread_impl.h"
2
3 int pthread_rwlock_unlock(pthread_rwlock_t *rw)
4 {
5         struct pthread *self = pthread_self();
6         if (rw->_rw_owner == self->tid) {
7                 rw->_rw_owner = 0;
8                 a_store(&rw->_rw_wrlock, 0);
9                 if (rw->_rw_waiters)
10                         __wake(&rw->_rw_wrlock, -1, 0);
11                 return 0;
12         }
13         a_dec(&rw->_rw_readers);
14         if (rw->_rw_waiters && !rw->_rw_readers)
15                 __wake(&rw->_rw_readers, 1, 0);
16         return 0;
17 }