mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-13 14:40:22 +00:00
In order to avoid recursing on the backing mutex for sx locks in the
INVARIANTS case, define the actual KASSERT() in _SX_ASSERT_[SX]LOCKED macros that are used in the sx code itself and convert the SX_ASSERT_[SX]LOCKED macros to simple wrappers that grab the mutex for the duration of the check.
This commit is contained in:
parent
e480e1ab93
commit
7331c2a252
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=73901
@ -136,7 +136,7 @@ sx_sunlock(struct sx *sx)
|
||||
{
|
||||
|
||||
mtx_lock(&sx->sx_lock);
|
||||
SX_ASSERT_SLOCKED(sx);
|
||||
_SX_ASSERT_SLOCKED(sx);
|
||||
|
||||
/* Release. */
|
||||
sx->sx_cnt--;
|
||||
@ -161,7 +161,7 @@ sx_xunlock(struct sx *sx)
|
||||
{
|
||||
|
||||
mtx_lock(&sx->sx_lock);
|
||||
SX_ASSERT_XLOCKED(sx);
|
||||
_SX_ASSERT_XLOCKED(sx);
|
||||
MPASS(sx->sx_cnt == -1);
|
||||
|
||||
/* Release. */
|
||||
|
12
sys/sys/sx.h
12
sys/sys/sx.h
@ -60,9 +60,12 @@ void sx_xunlock(struct sx *sx);
|
||||
*/
|
||||
#define SX_ASSERT_SLOCKED(sx) do { \
|
||||
mtx_lock(&(sx)->sx_lock); \
|
||||
_SX_ASSERT_SLOCKED((sx)); \
|
||||
mtx_unlock(&(sx)->sx_lock); \
|
||||
} while (0)
|
||||
#define _SX_ASSERT_SLOCKED(sx) do { \
|
||||
KASSERT(((sx)->sx_cnt > 0), ("%s: lacking slock %s\n", \
|
||||
__FUNCTION__, (sx)->sx_descr)); \
|
||||
mtx_unlock(&(sx)->sx_lock); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
@ -70,15 +73,20 @@ void sx_xunlock(struct sx *sx);
|
||||
*/
|
||||
#define SX_ASSERT_XLOCKED(sx) do { \
|
||||
mtx_lock(&(sx)->sx_lock); \
|
||||
_SX_ASSERT_XLOCKED((sx)); \
|
||||
mtx_unlock(&(sx)->sx_lock); \
|
||||
} while (0)
|
||||
#define _SX_ASSERT_XLOCKED(sx) do { \
|
||||
KASSERT(((sx)->sx_xholder == curproc), \
|
||||
("%s: thread %p lacking xlock %s\n", __FUNCTION__, \
|
||||
curproc, (sx)->sx_descr)); \
|
||||
mtx_unlock(&(sx)->sx_lock); \
|
||||
} while (0)
|
||||
|
||||
#else /* INVARIANTS */
|
||||
#define SX_ASSERT_SLOCKED(sx)
|
||||
#define SX_ASSERT_XLOCKED(sx)
|
||||
#define _SX_ASSERT_SLOCKED(sx)
|
||||
#define _SX_ASSERT_XLOCKED(sx)
|
||||
#endif /* INVARIANTS */
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
Loading…
Reference in New Issue
Block a user