From 8b37fbabb45fa792a44609fca23f56bea7380b34 Mon Sep 17 00:00:00 2001 From: David Xu Date: Sat, 25 Dec 2004 12:49:35 +0000 Subject: [PATCH] 1. introduce umtx_owner to get an owner of a umtx. 2. add const qualifier to umtx_timedlock and umtx_timedwait. 3. add missing blackets in umtx do_unlock_and_wait. --- sys/kern/kern_umtx.c | 4 +--- sys/sys/umtx.h | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index 3bc3a7829393..e00b9a6eff66 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -95,8 +95,6 @@ struct umtxq_chain { static struct umtxq_chain umtxq_chains[UMTX_CHAINS]; static MALLOC_DEFINE(M_UMTX, "umtx", "UMTX queue memory"); -#define UMTX_CONTESTED LONG_MIN - static void umtxq_init_chains(void *); static int umtxq_hash(struct umtx_key *key); static struct mtx *umtxq_mtx(int chain); @@ -682,7 +680,7 @@ do_unlock_and_wait(struct thread *td, struct umtx *umtx, long id, void *uaddr, error = umtxq_sleep(td, &uq.uq_key, td->td_priority | PCATCH, "ucond", timo); - if (!td->td_flags & TDF_UMTXQ) + if (!(td->td_flags & TDF_UMTXQ)) break; umtxq_unlock(&uq.uq_key); } diff --git a/sys/sys/umtx.h b/sys/sys/umtx.h index fdd359192adf..15d843472233 100644 --- a/sys/sys/umtx.h +++ b/sys/sys/umtx.h @@ -30,11 +30,14 @@ #ifndef _SYS_UMTX_H_ #define _SYS_UMTX_H_ +#include + /* * See pthread_* */ #define UMTX_UNOWNED 0x0 +#define UMTX_CONTESTED LONG_MIN struct umtx { void *u_owner; /* Owner of the mutex. */ @@ -62,6 +65,18 @@ int _umtx_op(struct umtx *umtx, int op, long id, void *uaddr, * Standard api. Try uncontested acquire/release and asks the * kernel to resolve failures. */ +static __inline void +umtx_init(struct umtx *umtx) +{ + umtx->u_owner = UMTX_UNOWNED; +} + +static __inline long +umtx_owner(struct umtx *umtx) +{ + return ((long)umtx->u_owner & ~LONG_MIN); +} + static __inline int umtx_lock(struct umtx *umtx, long id) { @@ -82,11 +97,11 @@ umtx_trylock(struct umtx *umtx, long id) } static __inline int -umtx_timedlock(struct umtx *umtx, long id, struct timespec *abstime) +umtx_timedlock(struct umtx *umtx, long id, const struct timespec *abstime) { if (atomic_cmpset_acq_ptr(&umtx->u_owner, (void *)UMTX_UNOWNED, (void *)id) == 0) - if (_umtx_op(umtx, UMTX_OP_LOCK, id, 0, abstime) == -1) + if (_umtx_op(umtx, UMTX_OP_LOCK, id, 0, (void *)abstime) == -1) return (errno); return (0); } @@ -113,9 +128,10 @@ umtx_wait(struct umtx *umtx, long id, void *uaddr) static __inline int umtx_timedwait(struct umtx *umtx, long id, void *uaddr, - struct timespec *abstime) + const struct timespec *abstime) { - if (_umtx_op(umtx, UMTX_OP_UNLOCK_AND_WAIT, id, uaddr, abstime) == -1) + if (_umtx_op(umtx, UMTX_OP_UNLOCK_AND_WAIT, id, uaddr, + (void *)abstime) == -1) return (errno); return (0); }