Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_lock.c
Show First 20 Lines • Show All 978 Lines • ▼ Show 20 Lines | lockmgr_upgrade(struct lock *lk, u_int flags, struct lock_object *ilk, | ||||
tid = (uintptr_t)curthread; | tid = (uintptr_t)curthread; | ||||
_lockmgr_assert(lk, KA_SLOCKED, file, line); | _lockmgr_assert(lk, KA_SLOCKED, file, line); | ||||
op = flags & LK_TYPE_MASK; | op = flags & LK_TYPE_MASK; | ||||
v = lockmgr_read_value(lk); | v = lockmgr_read_value(lk); | ||||
for (;;) { | for (;;) { | ||||
if (LK_SHARERS_LOCK(v) > 1) { | if (LK_SHARERS(v) > 1) { | ||||
cem: The cute spelling would be `v > LK_SHARERS_LOCK(1)`, which may have been the intent. | |||||
Not Done Inline Actions(Fail the tryupgrade if: (1) there are 2+ sharers, or (2) if any flag except LK_SHARE is set (i.e., there are waiters).) cem: (Fail the tryupgrade if: (1) there are 2+ sharers, or (2) if any flag except `LK_SHARE` is set… | |||||
if (op == LK_TRYUPGRADE) { | if (op == LK_TRYUPGRADE) { | ||||
LOCK_LOG2(lk, "%s: %p failed the nowait upgrade", | LOCK_LOG2(lk, "%s: %p failed the nowait upgrade", | ||||
__func__, lk); | __func__, lk); | ||||
error = EBUSY; | error = EBUSY; | ||||
goto out; | goto out; | ||||
} | } | ||||
if (lockmgr_sunlock_try(lk, &v)) { | if (atomic_fcmpset_rel_ptr(&lk->lk_lock, &v, | ||||
v - LK_ONE_SHARER)) { | |||||
lockmgr_note_shared_release(lk, file, line); | lockmgr_note_shared_release(lk, file, line); | ||||
goto out_xlock; | goto out_xlock; | ||||
} | } | ||||
continue; | |||||
} | } | ||||
MPASS((v & ~LK_ALL_WAITERS) == LK_SHARERS_LOCK(1)); | MPASS((v & ~LK_ALL_WAITERS) == LK_SHARERS_LOCK(1)); | ||||
setv = tid; | setv = tid; | ||||
setv |= (v & LK_ALL_WAITERS); | setv |= (v & LK_ALL_WAITERS); | ||||
/* | /* | ||||
* Try to switch from one shared lock to an exclusive one. | * Try to switch from one shared lock to an exclusive one. | ||||
▲ Show 20 Lines • Show All 846 Lines • Show Last 20 Lines |
The cute spelling would be v > LK_SHARERS_LOCK(1), which may have been the intent.