From 77e7cda2cf95ba670c85a1965aff38d2f83b484a Mon Sep 17 00:00:00 2001 From: davidxu Date: Mon, 28 Aug 2006 04:47:27 +0000 Subject: Add umutex APIs. --- lib/libthr/thread/thr_umtx.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'lib/libthr/thread/thr_umtx.c') diff --git a/lib/libthr/thread/thr_umtx.c b/lib/libthr/thread/thr_umtx.c index cba6942..a42091b 100644 --- a/lib/libthr/thread/thr_umtx.c +++ b/lib/libthr/thread/thr_umtx.c @@ -62,6 +62,52 @@ __thr_umtx_unlock(volatile umtx_t *mtx, long id) } int +__thr_umutex_lock(struct umutex *mtx, uint32_t id) +{ + if (_umtx_op(mtx, UMTX_OP_MUTEX_LOCK, 0, 0, 0) == 0) + return 0; + return (errno); +} + +int +__thr_umutex_timedlock(struct umutex *mtx, uint32_t id, + const struct timespec *timeout) +{ + 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)) == 0) + return (0); + return (errno); +} + +int +__thr_umutex_unlock(struct umutex *mtx, uint32_t id) +{ + if (_umtx_op(mtx, UMTX_OP_MUTEX_UNLOCK, 0, 0, 0) == 0) + return (0); + return (errno); +} + +int +__thr_umutex_kern_trylock(struct umutex *mtx) +{ + if (_umtx_op(mtx, UMTX_OP_MUTEX_TRYLOCK, 0, 0, 0) == 0) + return (0); + return (errno); +} + +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) == 0) + return (0); + return (errno); +} + +int _thr_umtx_wait(volatile umtx_t *mtx, long id, const struct timespec *timeout) { if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && -- cgit v1.1