aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2007-05-19 16:35:27 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2007-05-19 16:35:27 +0000
commitb0d673254df234f85fb1e05f4bc1d286c9b9684d (patch)
tree24c4105607db611659cd8034f65b27a2706cd007
parent705fda849d96eb65280573f3bf9daf348a76ea27 (diff)
Notes
-rw-r--r--sys/kern/kern_sx.c10
-rw-r--r--sys/sys/sx.h1
2 files changed, 9 insertions, 2 deletions
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c
index 9ecba95f7c6d..3a0973a2d691 100644
--- a/sys/kern/kern_sx.c
+++ b/sys/kern/kern_sx.c
@@ -170,6 +170,9 @@ sx_init_flags(struct sx *sx, const char *description, int opts)
{
int flags;
+ MPASS((opts & ~(SX_QUIET | SX_RECURSE | SX_NOWITNESS | SX_DUPOK |
+ SX_NOPROFILE)) == 0);
+
flags = LO_SLEEPABLE | LO_UPGRADABLE | LO_RECURSABLE;
if (opts & SX_DUPOK)
flags |= LO_DUPOK;
@@ -180,7 +183,7 @@ sx_init_flags(struct sx *sx, const char *description, int opts)
if (opts & SX_QUIET)
flags |= LO_QUIET;
- flags |= opts & SX_ADAPTIVESPIN;
+ flags |= opts & (SX_ADAPTIVESPIN | SX_RECURSE);
sx->sx_lock = SX_LOCK_UNLOCKED;
sx->sx_recurse = 0;
lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags);
@@ -254,7 +257,7 @@ _sx_try_xlock(struct sx *sx, const char *file, int line)
KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
("sx_try_xlock() of destroyed sx @ %s:%d", file, line));
- if (sx_xlocked(sx)) {
+ if (sx_xlocked(sx) && (sx->lock_object.lo_flags & SX_RECURSE) != 0) {
sx->sx_recurse++;
atomic_set_ptr(&sx->sx_lock, SX_LOCK_RECURSED);
rval = 1;
@@ -412,6 +415,9 @@ _sx_xlock_hard(struct sx *sx, uintptr_t tid, const char *file, int line)
/* If we already hold an exclusive lock, then recurse. */
if (sx_xlocked(sx)) {
+ KASSERT((sx->lock_object.lo_flags & SX_RECURSE) != 0,
+ ("_sx_xlock_hard: recursed on non-recursive sx %s @ %s:%d\n",
+ sx->lock_object.lo_name, file, line));
sx->sx_recurse++;
atomic_set_ptr(&sx->sx_lock, SX_LOCK_RECURSED);
if (LOCK_LOG_TEST(&sx->lock_object, 0))
diff --git a/sys/sys/sx.h b/sys/sys/sx.h
index d2688e1ec654..78f7df5e06fd 100644
--- a/sys/sys/sx.h
+++ b/sys/sys/sx.h
@@ -235,6 +235,7 @@ struct sx_args {
#define SX_NOWITNESS 0x04
#define SX_QUIET 0x08
#define SX_ADAPTIVESPIN 0x10
+#define SX_RECURSE 0x20
/*
* XXX: These options should be renamed as SA_*