summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2009-06-02 13:03:35 +0000
committerattilio <attilio@FreeBSD.org>2009-06-02 13:03:35 +0000
commit44c490ae17f695a91f5103b5ac4fa0448be2455f (patch)
tree0574452322c16cb1cd1a6d29e497620399499dff /sys/kern
parent0937475a4fb805678e611b218d2687ff0fe43637 (diff)
downloadFreeBSD-src-44c490ae17f695a91f5103b5ac4fa0448be2455f.zip
FreeBSD-src-44c490ae17f695a91f5103b5ac4fa0448be2455f.tar.gz
Handle lock recursion differenty by always checking against LO_RECURSABLE
instead the lock own flag itself. Tested by: pho
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_lock.c11
-rw-r--r--sys/kern/kern_rwlock.c12
-rw-r--r--sys/kern/kern_sx.c14
3 files changed, 20 insertions, 17 deletions
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index f03ddbc..c365e65 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -51,8 +51,7 @@ __FBSDID("$FreeBSD$");
#include <ddb/ddb.h>
#endif
-CTASSERT(((LK_CANRECURSE | LK_NOSHARE) & LO_CLASSFLAGS) ==
- (LK_CANRECURSE | LK_NOSHARE));
+CTASSERT((LK_NOSHARE & LO_CLASSFLAGS) == LK_NOSHARE);
#define SQ_EXCLUSIVE_QUEUE 0
#define SQ_SHARED_QUEUE 1
@@ -316,7 +315,9 @@ lockinit(struct lock *lk, int pri, const char *wmesg, int timo, int flags)
MPASS((flags & ~LK_INIT_MASK) == 0);
- iflags = LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE;
+ iflags = LO_SLEEPABLE | LO_UPGRADABLE;
+ if (flags & LK_CANRECURSE)
+ iflags |= LO_RECURSABLE;
if ((flags & LK_NODUP) == 0)
iflags |= LO_DUPOK;
if (flags & LK_NOPROFILE)
@@ -325,7 +326,7 @@ lockinit(struct lock *lk, int pri, const char *wmesg, int timo, int flags)
iflags |= LO_WITNESS;
if (flags & LK_QUIET)
iflags |= LO_QUIET;
- iflags |= flags & (LK_CANRECURSE | LK_NOSHARE);
+ iflags |= flags & LK_NOSHARE;
lk->lk_lock = LK_UNLOCKED;
lk->lk_recurse = 0;
@@ -530,7 +531,7 @@ __lockmgr_args(struct lock *lk, u_int flags, struct lock_object *ilk,
*/
if (lockmgr_xlocked(lk)) {
if ((flags & LK_CANRECURSE) == 0 &&
- (lk->lock_object.lo_flags & LK_CANRECURSE) == 0) {
+ (lk->lock_object.lo_flags & LO_RECURSABLE) == 0) {
/*
* If the lock is expected to not panic just
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index 28fccce..c07f595 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -51,8 +51,6 @@ __FBSDID("$FreeBSD$");
#include <machine/cpu.h>
-CTASSERT((RW_RECURSE & LO_CLASSFLAGS) == RW_RECURSE);
-
#if defined(SMP) && !defined(NO_ADAPTIVE_RWLOCKS)
#define ADAPTIVE_RWLOCKS
#endif
@@ -177,16 +175,17 @@ rw_init_flags(struct rwlock *rw, const char *name, int opts)
MPASS((opts & ~(RW_DUPOK | RW_NOPROFILE | RW_NOWITNESS | RW_QUIET |
RW_RECURSE)) == 0);
- flags = LO_UPGRADABLE | LO_RECURSABLE;
+ flags = LO_UPGRADABLE;
if (opts & RW_DUPOK)
flags |= LO_DUPOK;
if (opts & RW_NOPROFILE)
flags |= LO_NOPROFILE;
if (!(opts & RW_NOWITNESS))
flags |= LO_WITNESS;
+ if (opts & RW_RECURSE)
+ flags |= LO_RECURSABLE;
if (opts & RW_QUIET)
flags |= LO_QUIET;
- flags |= opts & RW_RECURSE;
rw->rw_lock = RW_UNLOCKED;
rw->rw_recurse = 0;
@@ -249,7 +248,8 @@ _rw_try_wlock(struct rwlock *rw, const char *file, int line)
KASSERT(rw->rw_lock != RW_DESTROYED,
("rw_try_wlock() of destroyed rwlock @ %s:%d", file, line));
- if (rw_wlocked(rw) && (rw->lock_object.lo_flags & RW_RECURSE) != 0) {
+ if (rw_wlocked(rw) &&
+ (rw->lock_object.lo_flags & LO_RECURSABLE) != 0) {
rw->rw_recurse++;
rval = 1;
} else
@@ -646,7 +646,7 @@ _rw_wlock_hard(struct rwlock *rw, uintptr_t tid, const char *file, int line)
#endif
if (rw_wlocked(rw)) {
- KASSERT(rw->lock_object.lo_flags & RW_RECURSE,
+ KASSERT(rw->lock_object.lo_flags & LO_RECURSABLE,
("%s: recursing but non-recursive rw %s @ %s:%d\n",
__func__, rw->lock_object.lo_name, file, line));
rw->rw_recurse++;
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c
index 6342252..04c2c98 100644
--- a/sys/kern/kern_sx.c
+++ b/sys/kern/kern_sx.c
@@ -66,8 +66,7 @@ __FBSDID("$FreeBSD$");
#define ADAPTIVE_SX
#endif
-CTASSERT(((SX_NOADAPTIVE | SX_RECURSE) & LO_CLASSFLAGS) ==
- (SX_NOADAPTIVE | SX_RECURSE));
+CTASSERT((SX_NOADAPTIVE & LO_CLASSFLAGS) == SX_NOADAPTIVE);
/* Handy macros for sleep queues. */
#define SQ_EXCLUSIVE_QUEUE 0
@@ -207,17 +206,19 @@ sx_init_flags(struct sx *sx, const char *description, int opts)
MPASS((opts & ~(SX_QUIET | SX_RECURSE | SX_NOWITNESS | SX_DUPOK |
SX_NOPROFILE | SX_NOADAPTIVE)) == 0);
- flags = LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE;
+ flags = LO_SLEEPABLE | LO_UPGRADABLE;
if (opts & SX_DUPOK)
flags |= LO_DUPOK;
if (opts & SX_NOPROFILE)
flags |= LO_NOPROFILE;
if (!(opts & SX_NOWITNESS))
flags |= LO_WITNESS;
+ if (opts & SX_RECURSE)
+ flags |= LO_RECURSABLE;
if (opts & SX_QUIET)
flags |= LO_QUIET;
- flags |= opts & (SX_NOADAPTIVE | SX_RECURSE);
+ flags |= opts & SX_NOADAPTIVE;
sx->sx_lock = SX_LOCK_UNLOCKED;
sx->sx_recurse = 0;
lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags);
@@ -305,7 +306,8 @@ _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) && (sx->lock_object.lo_flags & SX_RECURSE) != 0) {
+ if (sx_xlocked(sx) &&
+ (sx->lock_object.lo_flags & LO_RECURSABLE) != 0) {
sx->sx_recurse++;
atomic_set_ptr(&sx->sx_lock, SX_LOCK_RECURSED);
rval = 1;
@@ -479,7 +481,7 @@ _sx_xlock_hard(struct sx *sx, uintptr_t tid, int opts, const char *file,
/* If we already hold an exclusive lock, then recurse. */
if (sx_xlocked(sx)) {
- KASSERT((sx->lock_object.lo_flags & SX_RECURSE) != 0,
+ KASSERT((sx->lock_object.lo_flags & LO_RECURSABLE) != 0,
("_sx_xlock_hard: recursed on non-recursive sx %s @ %s:%d\n",
sx->lock_object.lo_name, file, line));
sx->sx_recurse++;
OpenPOWER on IntegriCloud