Files
semi-libc/src/thread/pthread_rwlock_unlock.c
T
Rich Felker 639bcf251e introduce namespace-safe rwlock aliases; use in pthread_key_create
commit 84d061d5a3 inadvertently
introduced namespace violations by using the pthread-namespace rwlock
functions in pthread_key_create, which is in turn used for C11 tss.
fix that and possible future uses of rwlocks elsewhere.
2019-02-16 11:44:07 -05:00

21 lines
467 B
C

#include "pthread_impl.h"
int __pthread_rwlock_unlock(pthread_rwlock_t *rw)
{
int val, cnt, waiters, new, priv = rw->_rw_shared^128;
do {
val = rw->_rw_lock;
cnt = val & 0x7fffffff;
waiters = rw->_rw_waiters;
new = (cnt == 0x7fffffff || cnt == 1) ? 0 : val-1;
} while (a_cas(&rw->_rw_lock, val, new) != val);
if (!new && (waiters || val<0))
__wake(&rw->_rw_lock, cnt, priv);
return 0;
}
weak_alias(__pthread_rwlock_unlock, pthread_rwlock_unlock);