diff options
Diffstat (limited to 'lib/libthr/thread/thr_umtx.c')
-rw-r--r-- | lib/libthr/thread/thr_umtx.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_umtx.c b/lib/libthr/thread/thr_umtx.c index 5af923d..b712b7a 100644 --- a/lib/libthr/thread/thr_umtx.c +++ b/lib/libthr/thread/thr_umtx.c @@ -217,3 +217,42 @@ __thr_rwlock_unlock(struct urwlock *rwlock) { return _umtx_op_err(rwlock, UMTX_OP_RW_UNLOCK, 0, NULL, NULL); } + +void +_thr_rwl_rdlock(struct urwlock *rwlock) +{ + int ret; + + for (;;) { + if (_thr_rwlock_tryrdlock(rwlock, URWLOCK_PREFER_READER) == 0) + return; + ret = __thr_rwlock_rdlock(rwlock, URWLOCK_PREFER_READER, NULL); + if (ret == 0) + return; + if (ret != EINTR) + PANIC("rdlock error"); + } +} + +void +_thr_rwl_wrlock(struct urwlock *rwlock) +{ + int ret; + + for (;;) { + if (_thr_rwlock_trywrlock(rwlock) == 0) + return; + ret = __thr_rwlock_wrlock(rwlock, NULL); + if (ret == 0) + return; + if (ret != EINTR) + PANIC("wrlock error"); + } +} + +void +_thr_rwl_unlock(struct urwlock *rwlock) +{ + if (_thr_rwlock_unlock(rwlock)) + PANIC("unlock error"); +} |