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.
This commit is contained in:
David Xu 2004-12-25 12:49:35 +00:00
parent 587161d920
commit 8b37fbabb4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=139291
2 changed files with 21 additions and 7 deletions

View File

@ -95,8 +95,6 @@ struct umtxq_chain {
static struct umtxq_chain umtxq_chains[UMTX_CHAINS]; static struct umtxq_chain umtxq_chains[UMTX_CHAINS];
static MALLOC_DEFINE(M_UMTX, "umtx", "UMTX queue memory"); static MALLOC_DEFINE(M_UMTX, "umtx", "UMTX queue memory");
#define UMTX_CONTESTED LONG_MIN
static void umtxq_init_chains(void *); static void umtxq_init_chains(void *);
static int umtxq_hash(struct umtx_key *key); static int umtxq_hash(struct umtx_key *key);
static struct mtx *umtxq_mtx(int chain); 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, error = umtxq_sleep(td, &uq.uq_key,
td->td_priority | PCATCH, td->td_priority | PCATCH,
"ucond", timo); "ucond", timo);
if (!td->td_flags & TDF_UMTXQ) if (!(td->td_flags & TDF_UMTXQ))
break; break;
umtxq_unlock(&uq.uq_key); umtxq_unlock(&uq.uq_key);
} }

View File

@ -30,11 +30,14 @@
#ifndef _SYS_UMTX_H_ #ifndef _SYS_UMTX_H_
#define _SYS_UMTX_H_ #define _SYS_UMTX_H_
#include <sys/limits.h>
/* /*
* See pthread_* * See pthread_*
*/ */
#define UMTX_UNOWNED 0x0 #define UMTX_UNOWNED 0x0
#define UMTX_CONTESTED LONG_MIN
struct umtx { struct umtx {
void *u_owner; /* Owner of the mutex. */ 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 * Standard api. Try uncontested acquire/release and asks the
* kernel to resolve failures. * 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 static __inline int
umtx_lock(struct umtx *umtx, long id) umtx_lock(struct umtx *umtx, long id)
{ {
@ -82,11 +97,11 @@ umtx_trylock(struct umtx *umtx, long id)
} }
static __inline int 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, if (atomic_cmpset_acq_ptr(&umtx->u_owner, (void *)UMTX_UNOWNED,
(void *)id) == 0) (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 (errno);
return (0); return (0);
} }
@ -113,9 +128,10 @@ umtx_wait(struct umtx *umtx, long id, void *uaddr)
static __inline int static __inline int
umtx_timedwait(struct umtx *umtx, long id, void *uaddr, 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 (errno);
return (0); return (0);
} }