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:
parent
587161d920
commit
8b37fbabb4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=139291
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user