diff options
Diffstat (limited to 'lib/libthr/thread/thr_umtx.c')
-rw-r--r-- | lib/libthr/thread/thr_umtx.c | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/lib/libthr/thread/thr_umtx.c b/lib/libthr/thread/thr_umtx.c index d0a225d..ff8c60e 100644 --- a/lib/libthr/thread/thr_umtx.c +++ b/lib/libthr/thread/thr_umtx.c @@ -30,6 +30,15 @@ #include "thr_private.h" #include "thr_umtx.h" +#ifndef HAS__UMTX_OP_ERR +int _umtx_op_err(void *obj, int op, u_long val, void *uaddr, void *uaddr2) +{ + if (_umtx_op(obj, op, val, uaddr, uaddr2) == -1) + return (errno); + return (0); +} +#endif + void _thr_umutex_init(struct umutex *mtx) { @@ -41,9 +50,7 @@ _thr_umutex_init(struct umutex *mtx) int __thr_umutex_lock(struct umutex *mtx) { - if (_umtx_op(mtx, UMTX_OP_MUTEX_LOCK, 0, 0, 0) != -1) - return 0; - return (errno); + return _umtx_op_err(mtx, UMTX_OP_MUTEX_LOCK, 0, 0, 0); } int @@ -53,35 +60,27 @@ __thr_umutex_timedlock(struct umutex *mtx, if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && timeout->tv_nsec <= 0))) return (ETIMEDOUT); - if (_umtx_op(mtx, UMTX_OP_MUTEX_LOCK, 0, 0, - __DECONST(void *, timeout)) != -1) - return (0); - return (errno); + return _umtx_op_err(mtx, UMTX_OP_MUTEX_LOCK, 0, 0, + __DECONST(void *, timeout)); } int __thr_umutex_unlock(struct umutex *mtx) { - if (_umtx_op(mtx, UMTX_OP_MUTEX_UNLOCK, 0, 0, 0) != -1) - return (0); - return (errno); + return _umtx_op_err(mtx, UMTX_OP_MUTEX_UNLOCK, 0, 0, 0); } int __thr_umutex_trylock(struct umutex *mtx) { - if (_umtx_op(mtx, UMTX_OP_MUTEX_TRYLOCK, 0, 0, 0) != -1) - return (0); - return (errno); + return _umtx_op_err(mtx, UMTX_OP_MUTEX_TRYLOCK, 0, 0, 0); } int __thr_umutex_set_ceiling(struct umutex *mtx, uint32_t ceiling, uint32_t *oldceiling) { - if (_umtx_op(mtx, UMTX_OP_SET_CEILING, ceiling, oldceiling, 0) != -1) - return (0); - return (errno); + return _umtx_op_err(mtx, UMTX_OP_SET_CEILING, ceiling, oldceiling, 0); } int @@ -90,10 +89,8 @@ _thr_umtx_wait(volatile long *mtx, long id, const struct timespec *timeout) if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && timeout->tv_nsec <= 0))) return (ETIMEDOUT); - if (_umtx_op(__DEVOLATILE(void *, mtx), UMTX_OP_WAIT, id, 0, - __DECONST(void*, timeout)) != -1) - return (0); - return (errno); + return _umtx_op_err(__DEVOLATILE(void *, mtx), UMTX_OP_WAIT, id, 0, + __DECONST(void*, timeout)); } int @@ -102,19 +99,15 @@ _thr_umtx_wait_uint(volatile u_int *mtx, u_int id, const struct timespec *timeou if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && timeout->tv_nsec <= 0))) return (ETIMEDOUT); - if (_umtx_op(__DEVOLATILE(void *, mtx), UMTX_OP_WAIT_UINT, id, 0, - __DECONST(void*, timeout)) != -1) - return (0); - return (errno); + return _umtx_op_err(__DEVOLATILE(void *, mtx), UMTX_OP_WAIT_UINT, id, 0, + __DECONST(void*, timeout)); } int _thr_umtx_wake(volatile void *mtx, int nr_wakeup) { - if (_umtx_op(__DEVOLATILE(void *, mtx), UMTX_OP_WAKE, - nr_wakeup, 0, 0) != -1) - return (0); - return (errno); + return _umtx_op_err(__DEVOLATILE(void *, mtx), UMTX_OP_WAKE, + nr_wakeup, 0, 0); } void @@ -132,12 +125,9 @@ _thr_ucond_wait(struct ucond *cv, struct umutex *m, __thr_umutex_unlock(m); return (ETIMEDOUT); } - if (_umtx_op(cv, UMTX_OP_CV_WAIT, + return _umtx_op_err(cv, UMTX_OP_CV_WAIT, check_unparking ? UMTX_CHECK_UNPARKING : 0, - m, __DECONST(void*, timeout)) != -1) { - return (0); - } - return (errno); + m, __DECONST(void*, timeout)); } int @@ -145,9 +135,7 @@ _thr_ucond_signal(struct ucond *cv) { if (!cv->c_has_waiters) return (0); - if (_umtx_op(cv, UMTX_OP_CV_SIGNAL, 0, NULL, NULL) != -1) - return (0); - return (errno); + return _umtx_op_err(cv, UMTX_OP_CV_SIGNAL, 0, NULL, NULL); } int @@ -155,31 +143,23 @@ _thr_ucond_broadcast(struct ucond *cv) { if (!cv->c_has_waiters) return (0); - if (_umtx_op(cv, UMTX_OP_CV_BROADCAST, 0, NULL, NULL) != -1) - return (0); - return (errno); + return _umtx_op_err(cv, UMTX_OP_CV_BROADCAST, 0, NULL, NULL); } int __thr_rwlock_rdlock(struct urwlock *rwlock, int flags, struct timespec *tsp) { - if (_umtx_op(rwlock, UMTX_OP_RW_RDLOCK, flags, NULL, tsp) != -1) - return (0); - return (errno); + return _umtx_op_err(rwlock, UMTX_OP_RW_RDLOCK, flags, NULL, tsp); } int __thr_rwlock_wrlock(struct urwlock *rwlock, struct timespec *tsp) { - if (_umtx_op(rwlock, UMTX_OP_RW_WRLOCK, 0, NULL, tsp) != -1) - return (0); - return (errno); + return _umtx_op_err(rwlock, UMTX_OP_RW_WRLOCK, 0, NULL, tsp); } int __thr_rwlock_unlock(struct urwlock *rwlock) { - if (_umtx_op(rwlock, UMTX_OP_RW_UNLOCK, 0, NULL, NULL) != -1) - return (0); - return (errno); + return _umtx_op_err(rwlock, UMTX_OP_RW_UNLOCK, 0, NULL, NULL); } |