1
0
mirror of https://git.FreeBSD.org/src.git synced 2026-06-02 11:24:32 +00:00

mtx: retire _mtx_release_lock_quick

The macro is misleading and of questionable value to begin with.

For starters, it is used for both spinlocks and regular mutexes (the
latter only the in the slow path), which have fundamentally different
requirements on unlock -- spinlocks are guaranteed to not have blocked
waiters and can blindly do a store.

The commentary above the it is also head-scratching:
> Release mtx_lock quickly, assuming we own it.

You can't *just* release a sleepable mutex "quickly". The only legal use
right now is when the turnstile lock is held.

Note that unlock of a sleepable mutex without using RMW atomics is very
much possible and may show up soon (tm).

Sponsored by:	Rubicon Communications, LLC ("Netgate")
This commit is contained in:
Mateusz Guzik
2025-10-05 15:38:06 +00:00
parent d0a35ec01c
commit ccb600906f
2 changed files with 4 additions and 8 deletions
+3 -3
View File
@@ -869,7 +869,7 @@ _thread_lock(struct thread *td)
WITNESS_LOCK(&m->lock_object, LOP_EXCLUSIVE, file, line);
return;
}
_mtx_release_lock_quick(m);
atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED);
slowpath_unlocked:
spinlock_exit();
slowpath_noirq:
@@ -959,7 +959,7 @@ retry:
}
if (m == td->td_lock)
break;
_mtx_release_lock_quick(m);
atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED);
}
LOCK_LOG_LOCK("LOCK", &m->lock_object, opts, m->mtx_recurse, file,
line);
@@ -1071,7 +1071,7 @@ __mtx_unlock_sleep(volatile uintptr_t *c, uintptr_t v)
* can be removed from the hash list if it is empty.
*/
turnstile_chain_lock(&m->lock_object);
_mtx_release_lock_quick(m);
atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED);
ts = turnstile_lookup(&m->lock_object);
MPASS(ts != NULL);
if (LOCK_LOG_TEST(&m->lock_object, opts))
+1 -5
View File
@@ -221,10 +221,6 @@ void _thread_lock(struct thread *);
#define _mtx_release_lock(mp, tid) \
atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), MTX_UNOWNED)
/* Release mtx_lock quickly, assuming we own it. */
#define _mtx_release_lock_quick(mp) \
atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED)
#define _mtx_release_lock_fetch(mp, vp) \
atomic_fcmpset_rel_ptr(&(mp)->mtx_lock, (vp), MTX_UNOWNED)
@@ -332,7 +328,7 @@ void _thread_lock(struct thread *);
(mp)->mtx_recurse--; \
else { \
LOCKSTAT_PROFILE_RELEASE_SPIN_LOCK(spin__release, mp); \
_mtx_release_lock_quick((mp)); \
atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED); \
} \
spinlock_exit(); \
})