aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_sx.c
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2001-10-23 22:39:11 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2001-10-23 22:39:11 +0000
commit4e5e677bc09b04779ca78ed11e8dcb5e8bca692b (patch)
tree01dcac73fae7ff5bfe14b5b70a3438318b77a47d /sys/kern/kern_sx.c
parente5e5b51f9f11601c89829a05ae2cdd02cdbbc648 (diff)
downloadsrc-4e5e677bc09b04779ca78ed11e8dcb5e8bca692b.tar.gz
src-4e5e677bc09b04779ca78ed11e8dcb5e8bca692b.zip
Change the sx(9) assertion API to use a sx_assert() function similar to
mtx_assert(9) rather than several SX_ASSERT_* macros.
Notes
Notes: svn path=/head/; revision=85388
Diffstat (limited to 'sys/kern/kern_sx.c')
-rw-r--r--sys/kern/kern_sx.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c
index 5323ea0253ea..5408af4de4fa 100644
--- a/sys/kern/kern_sx.c
+++ b/sys/kern/kern_sx.c
@@ -197,8 +197,8 @@ void
_sx_sunlock(struct sx *sx, const char *file, int line)
{
+ _sx_assert(sx, SX_SLOCKED, file, line);
mtx_lock(&sx->sx_lock);
- _SX_ASSERT_SLOCKED(sx, file, line);
WITNESS_UNLOCK(&sx->sx_object, 0, file, line);
@@ -226,8 +226,8 @@ void
_sx_xunlock(struct sx *sx, const char *file, int line)
{
+ _sx_assert(sx, SX_XLOCKED, file, line);
mtx_lock(&sx->sx_lock);
- _SX_ASSERT_XLOCKED(sx, file, line);
MPASS(sx->sx_cnt == -1);
WITNESS_UNLOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line);
@@ -253,8 +253,8 @@ int
_sx_try_upgrade(struct sx *sx, const char *file, int line)
{
+ _sx_assert(sx, SX_SLOCKED, file, line);
mtx_lock(&sx->sx_lock);
- _SX_ASSERT_SLOCKED(sx, file, line);
if (sx->sx_cnt == 1) {
sx->sx_cnt = -1;
@@ -277,8 +277,8 @@ void
_sx_downgrade(struct sx *sx, const char *file, int line)
{
+ _sx_assert(sx, SX_XLOCKED, file, line);
mtx_lock(&sx->sx_lock);
- _SX_ASSERT_XLOCKED(sx, file, line);
MPASS(sx->sx_cnt == -1);
WITNESS_DOWNGRADE(&sx->sx_object, 0, file, line);
@@ -292,3 +292,42 @@ _sx_downgrade(struct sx *sx, const char *file, int line)
mtx_unlock(&sx->sx_lock);
}
+
+#ifdef INVARIANT_SUPPORT
+/*
+ * In the non-WITNESS case, sx_assert() can only detect that at least
+ * *some* thread owns an slock, but it cannot guarantee that *this*
+ * thread owns an slock.
+ */
+void
+_sx_assert(struct sx *sx, int what, const char *file, int line)
+{
+
+ switch (what) {
+ case SX_LOCKED:
+ case SX_SLOCKED:
+#ifdef WITNESS
+ witness_assert(&sx->sx_object, what, file, line);
+#else
+ mtx_lock(&sx->sx_lock);
+ if (sx->sx_cnt <= 0 &&
+ (what == SX_SLOCKED || sx->sx_xholder == curthread))
+ printf("Lock %s not %slocked @ %s:%d",
+ sx->sx_object.lo_name, (what == SX_SLOCKED) ?
+ "share " : "", file, line);
+ mtx_unlock(&sx->sx_lock);
+#endif
+ break;
+ case SX_XLOCKED:
+ mtx_lock(&sx->sx_lock);
+ if (sx->sx_xholder != curthread)
+ printf("Lock %s not exclusively locked @ %s:%d",
+ sx->sx_object.lo_name, file, line);
+ mtx_unlock(&sx->sx_lock);
+ break;
+ default:
+ panic("Unknown sx lock assertion: %d @ %s:%d", what, file,
+ line);
+ }
+}
+#endif /* INVARIANT_SUPPORT */