f39117e743ee75c20a420f8ecfec1d336adb8d42
[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->__owner == self->tid) {
7                 rw->__owner = 0;
8                 a_store(&rw->__wrlock, 0);
9                 if (rw->__waiters)
10                         __wake(&rw->__wrlock, -1, 0);
11                 return 0;
12         }
13         a_dec(&rw->__readers);
14         if (rw->__waiters && !rw->__readers)
15                 __wake(&rw->__readers, 1, 0);
16         return 0;
17 }