]> git.proxmox.com Git - wasi-libc.git/blame - libc-top-half/musl/src/thread/pthread_rwlock_timedwrlock.c
Update to musl 1.1.22.
[wasi-libc.git] / libc-top-half / musl / src / thread / pthread_rwlock_timedwrlock.c
CommitLineData
320054e8
DG
1#include "pthread_impl.h"
2
f41256b6 3int __pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
320054e8
DG
4{
5 int r, t;
6
7 r = pthread_rwlock_trywrlock(rw);
8 if (r != EBUSY) return r;
9
10 int spins = 100;
11 while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin();
12
f41256b6 13 while ((r=__pthread_rwlock_trywrlock(rw))==EBUSY) {
320054e8
DG
14 if (!(r=rw->_rw_lock)) continue;
15 t = r | 0x80000000;
16 a_inc(&rw->_rw_waiters);
17 a_cas(&rw->_rw_lock, r, t);
18 r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128);
19 a_dec(&rw->_rw_waiters);
20 if (r && r != EINTR) return r;
21 }
22 return r;
23}
f41256b6
DG
24
25weak_alias(__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock);