summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2004-12-25 12:49:35 +0000
committerdavidxu <davidxu@FreeBSD.org>2004-12-25 12:49:35 +0000
commit7b03c7ecc4225f3c91f0ca8226a08c5f578c1baa (patch)
tree362edeca7663f30de9ad99278f01a8f81a939df1 /sys
parentaa3fdaa2efc844f93870359e85ba1f69d94ee3ad (diff)
downloadFreeBSD-src-7b03c7ecc4225f3c91f0ca8226a08c5f578c1baa.zip
FreeBSD-src-7b03c7ecc4225f3c91f0ca8226a08c5f578c1baa.tar.gz
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_umtx.c4
-rw-r--r--sys/sys/umtx.h24
2 files changed, 21 insertions, 7 deletions
diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index 3bc3a78..e00b9a6 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 fdd3591..15d8434 100644
--- a/sys/sys/umtx.h
+++ b/sys/sys/umtx.h
@@ -30,11 +30,14 @@
#ifndef _SYS_UMTX_H_
#define _SYS_UMTX_H_
+#include <sys/limits.h>
+
/*
* 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);
}
OpenPOWER on IntegriCloud