diff -ru /cvs/sys_old/kern/kern_mutex.c /usr/src/sys/kern/kern_mutex.c --- /cvs/sys_old/kern/kern_mutex.c Sat Jan 13 01:58:53 2001 +++ /usr/src/sys/kern/kern_mutex.c Sat Jan 13 15:06:04 2001 @@ -88,11 +88,11 @@ #ifdef WITNESS static struct mtx_debug all_mtx_debug = { NULL, {NULL, NULL}, NULL, 0, "All mutexes queue head" }; -static struct mtx all_mtx = { MTX_UNOWNED, 0, 0, &all_mtx_debug, +static struct mtx all_mtx = { MTX_UNOWNED, 0, 0, 0, &all_mtx_debug, TAILQ_HEAD_INITIALIZER(all_mtx.mtx_blocked), { NULL, NULL }, &all_mtx, &all_mtx }; #else /* WITNESS */ -static struct mtx all_mtx = { MTX_UNOWNED, 0, 0, "All mutexes queue head", +static struct mtx all_mtx = { MTX_UNOWNED, 0, 0, 0, "All mutexes queue head", TAILQ_HEAD_INITIALIZER(all_mtx.mtx_blocked), { NULL, NULL }, &all_mtx, &all_mtx }; #endif /* WITNESS */ @@ -257,7 +257,9 @@ switch (type) { case MTX_DEF: - if ((m->mtx_lock & MTX_FLAGMASK) == (uintptr_t)p) { + if (((m->mtx_lock & MTX_FLAGMASK) == (uintptr_t)p)) { + KASSERT(m->mtx_type & MTX_RECUR, + ("Attempting to recurse on a non-recursive lock.")); m->mtx_recurse++; atomic_set_ptr(&m->mtx_lock, MTX_RECURSE); if ((type & MTX_QUIET) == 0) @@ -284,7 +286,7 @@ uintptr_t v; struct proc *p1; - mtx_enter(&sched_lock, MTX_SPIN | MTX_RLIKELY); + mtx_enter(&sched_lock, MTX_SPIN); /* * check if the lock has been released while * waiting for the schedlock. @@ -385,6 +387,8 @@ int i = 0; if (m->mtx_lock == (uintptr_t)p) { + KASSERT(m->mtx_type & MTX_RECUR, + ("Attempting to recurse on a non-recursive lock.")); m->mtx_recurse++; return; } @@ -434,7 +438,9 @@ switch (type) { case MTX_DEF: case MTX_DEF | MTX_NOSWITCH: - if (m->mtx_recurse != 0) { + if (mtx_recursed(m)) { + KASSERT(m->mtx_type & MTX_RECUR, + ("Dropping recurse cnt on a non-recursive lock.")); if (--(m->mtx_recurse) == 0) atomic_clear_ptr(&m->mtx_lock, MTX_RECURSE); if ((type & MTX_QUIET) == 0) @@ -501,7 +507,9 @@ break; case MTX_SPIN: case MTX_SPIN | MTX_FIRST: - if (m->mtx_recurse != 0) { + if (mtx_recursed(m)) { + KASSERT(m->mtx_type & MTX_RECUR, + ("Dropping recurse cnt on a non-recursive lock.")); m->mtx_recurse--; return; } @@ -515,7 +523,9 @@ } break; case MTX_SPIN | MTX_TOPHALF: - if (m->mtx_recurse != 0) { + if (mtx_recursed(m)) { + KASSERT(m->mtx_type & MTX_RECUR, + ("Dropping recurse cnt on a non-recursive lock.")); m->mtx_recurse--; return; } @@ -630,6 +640,9 @@ #endif m->mtx_description = t; m->mtx_lock = MTX_UNOWNED; + + m->mtx_type |= (flag & MTX_RECUR); + /* Put on all mutex queue */ mtx_enter(&all_mtx, MTX_DEF); m->mtx_next = &all_mtx; @@ -841,7 +854,7 @@ if (!w->w_spin) panic("mutex_enter: MTX_SPIN on MTX_DEF mutex %s @" " %s:%d", m->mtx_description, file, line); - if (m->mtx_recurse != 0) + if (mtx_recursed(m)) return; mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); i = PCPU_GET(witness_spin_check); @@ -864,7 +877,7 @@ panic("mutex_enter: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", m->mtx_description, file, line); - if (m->mtx_recurse != 0) + if (mtx_recursed(m)) return; if (witness_dead) goto out; @@ -974,7 +987,7 @@ if (!w->w_spin) panic("mutex_exit: MTX_SPIN on MTX_DEF mutex %s @" " %s:%d", m->mtx_description, file, line); - if (m->mtx_recurse != 0) + if (mtx_recursed(m)) return; mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); PCPU_SET(witness_spin_check, @@ -986,7 +999,7 @@ panic("mutex_exit: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", m->mtx_description, file, line); - if (m->mtx_recurse != 0) + if (mtx_recursed(m)) return; if ((flags & MTX_NOSWITCH) == 0 && !mtx_legal2block() && !cold) @@ -1009,7 +1022,7 @@ panic("mutex_try_enter: " "MTX_SPIN on MTX_DEF mutex %s @ %s:%d", m->mtx_description, file, line); - if (m->mtx_recurse != 0) + if (mtx_recursed(m)) return; mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); PCPU_SET(witness_spin_check, @@ -1026,7 +1039,7 @@ panic("mutex_try_enter: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", m->mtx_description, file, line); - if (m->mtx_recurse != 0) + if (mtx_recursed(m)) return; w->w_file = file; diff -ru /cvs/sys_old/sys/mutex.h /usr/src/sys/sys/mutex.h --- /cvs/sys_old/sys/mutex.h Sat Jan 13 01:59:29 2001 +++ /usr/src/sys/sys/mutex.h Sat Jan 13 03:47:42 2001 @@ -63,12 +63,11 @@ * * Types */ -#define MTX_DEF 0x0 /* Default (spin/sleep) */ -#define MTX_SPIN 0x1 /* Spin only lock */ +#define MTX_DEF 0x00000000 /* Default (spin/sleep) */ +#define MTX_SPIN 0x00000001 /* Spin only lock */ +#define MTX_RECUR 0x00000002 /* Recursive lock */ /* Options */ -#define MTX_RLIKELY 0x4 /* (opt) Recursion likely */ -#define MTX_NORECURSE 0x8 /* No recursion possible */ #define MTX_NOSPIN 0x10 /* Don't spin before sleeping */ #define MTX_NOSWITCH 0x20 /* Do not switch on release */ #define MTX_FIRST 0x40 /* First spin lock holder */ @@ -109,6 +108,7 @@ struct mtx { volatile uintptr_t mtx_lock; /* lock owner/gate/flags */ volatile u_int mtx_recurse; /* number of recursive holds */ + u_int mtx_type; /* lock type */ u_int mtx_saveintr; /* saved flags (for spin locks) */ #ifdef WITNESS struct mtx_debug *mtx_debug; @@ -453,7 +453,7 @@ char STR_mtx_enter_fmt[] = "GOT %s [%p] r=%d at %s:%d"; char STR_mtx_exit_fmt[] = "REL %s [%p] r=%d at %s:%d"; char STR_mtx_try_enter_fmt[] = "TRY_ENTER %s [%p] result=%d at %s:%d"; -char STR_mtx_bad_type[] = "((type) & (MTX_NORECURSE | MTX_NOSWITCH)) == 0"; +char STR_mtx_bad_type[] = "((type) & MTX_NOSWITCH) == 0"; char STR_mtx_owned[] = "mtx_owned(mpp)"; char STR_mtx_recurse[] = "mpp->mtx_recurse == 0"; #else /* _KERN_MUTEX_C_ */ @@ -478,19 +478,18 @@ struct mtx *mpp = mtxp; /* bits only valid on mtx_exit() */ - MPASS4(((type) & (MTX_NORECURSE | MTX_NOSWITCH)) == 0, - STR_mtx_bad_type, file, line); + MPASS4(((type) & MTX_NOSWITCH) == 0, STR_mtx_bad_type, file, line); if ((type) & MTX_SPIN) { /* * Easy cases of spin locks: * * 1) We already own the lock and will simply recurse on it (if - * RLIKELY) + * RECUR) * * 2) The lock is free, we just get it */ - if ((type) & MTX_RLIKELY) { + if (mpp->mtx_type & MTX_RECUR) { /* * Check for recursion, if we already have this * lock we just bump the recursion count. @@ -519,7 +518,7 @@ _getlock_norecurse(mpp, CURTHD, (type) & MTX_HARDOPTS); } else { /* Sleep locks */ - if ((type) & MTX_RLIKELY) + if (mpp->mtx_type & MTX_RECUR) _getlock_sleep(mpp, CURTHD, (type) & MTX_HARDOPTS); else _getlock_norecurse(mpp, CURTHD, (type) & MTX_HARDOPTS); @@ -571,7 +570,7 @@ CTR5(KTR_LOCK, STR_mtx_exit_fmt, mpp->mtx_description, mpp, mpp->mtx_recurse, file, line); if ((type) & MTX_SPIN) { - if ((type) & MTX_NORECURSE) { + if ((mpp->mtx_type & MTX_RECUR) == 0) { int mtx_intr = mpp->mtx_saveintr; MPASS4(mpp->mtx_recurse == 0, STR_mtx_recurse, @@ -594,7 +593,7 @@ } } else { /* Handle sleep locks */ - if ((type) & MTX_RLIKELY) + if (mpp->mtx_type & MTX_RECUR) _exitlock(mpp, CURTHD, (type) & MTX_HARDOPTS); else { _exitlock_norecurse(mpp, CURTHD,