mtx: add mtx_wait_unlocked
This commit is contained in:
parent
3cf4e11179
commit
a83b4ff63f
@ -1275,6 +1275,35 @@ mtx_spin_wait_unlocked(struct mtx *m)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mtx_wait_unlocked(struct mtx *m)
|
||||
{
|
||||
struct thread *owner;
|
||||
uintptr_t v;
|
||||
|
||||
KASSERT(m->mtx_lock != MTX_DESTROYED,
|
||||
("%s() of destroyed mutex %p", __func__, m));
|
||||
KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_sleep,
|
||||
("%s() not a sleep mutex %p (%s)", __func__, m,
|
||||
m->lock_object.lo_name));
|
||||
KASSERT(!mtx_owned(m), ("%s() waiting on myself on lock %p (%s)", __func__, m,
|
||||
m->lock_object.lo_name));
|
||||
|
||||
for (;;) {
|
||||
v = atomic_load_acq_ptr(&m->mtx_lock);
|
||||
if (v == MTX_UNOWNED) {
|
||||
break;
|
||||
}
|
||||
owner = lv_mtx_owner(v);
|
||||
if (!TD_IS_RUNNING(owner)) {
|
||||
mtx_lock(m);
|
||||
mtx_unlock(m);
|
||||
break;
|
||||
}
|
||||
cpu_spinwait();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DDB
|
||||
void
|
||||
db_show_mtx(const struct lock_object *lock)
|
||||
|
@ -106,6 +106,7 @@ void __mtx_unlock_sleep(volatile uintptr_t *c, uintptr_t v, int opts,
|
||||
void __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v);
|
||||
void __mtx_unlock_sleep(volatile uintptr_t *c, uintptr_t v);
|
||||
#endif
|
||||
void mtx_wait_unlocked(struct mtx *m);
|
||||
|
||||
#ifdef SMP
|
||||
#if LOCK_DEBUG > 0
|
||||
|
Loading…
Reference in New Issue
Block a user