diff -ru /cvs/sys_old/kern/kern_mutex.c /usr/src/sys/kern/kern_mutex.c --- /cvs/sys_old/kern/kern_mutex.c Tue Jan 16 22:08:00 2001 +++ /usr/src/sys/kern/kern_mutex.c Tue Jan 16 22:53:12 2001 @@ -259,7 +259,7 @@ case MTX_DEF: if ((m->mtx_lock & MTX_FLAGMASK) == (uintptr_t)p) { m->mtx_recurse++; - atomic_set_ptr(&m->mtx_lock, MTX_RECURSE); + atomic_set_ptr(&m->mtx_lock, MTX_RECURSED); if ((type & MTX_QUIET) == 0) CTR1(KTR_LOCK, "mtx_enter: 0x%p recurse", m); return; @@ -434,9 +434,9 @@ switch (type) { case MTX_DEF: case MTX_DEF | MTX_NOSWITCH: - if (m->mtx_recurse != 0) { + if (mtx_recursed(m)) { if (--(m->mtx_recurse) == 0) - atomic_clear_ptr(&m->mtx_lock, MTX_RECURSE); + atomic_clear_ptr(&m->mtx_lock, MTX_RECURSED); if ((type & MTX_QUIET) == 0) CTR1(KTR_LOCK, "mtx_exit: 0x%p unrecurse", m); return; @@ -501,7 +501,7 @@ break; case MTX_SPIN: case MTX_SPIN | MTX_FIRST: - if (m->mtx_recurse != 0) { + if (mtx_recursed(m)) { m->mtx_recurse--; return; } @@ -515,7 +515,7 @@ } break; case MTX_SPIN | MTX_TOPHALF: - if (m->mtx_recurse != 0) { + if (mtx_recursed(m)) { m->mtx_recurse--; return; } @@ -655,7 +655,7 @@ if (!mtx_owned(m)) { MPASS(m->mtx_lock == MTX_UNOWNED); } else { - MPASS((m->mtx_lock & (MTX_RECURSE|MTX_CONTESTED)) == 0); + MPASS((m->mtx_lock & (MTX_RECURSED|MTX_CONTESTED)) == 0); } mtx_validate(m, MV_DESTROY); /* diagnostic */ #endif @@ -701,8 +701,7 @@ u_char w_Giant_squawked:1; u_char w_other_squawked:1; u_char w_same_squawked:1; - u_char w_sleep:1; - u_char w_spin:1; /* this is a spin mutex */ + int w_typeflg; /* type of mutex (spin, recursed, ...) */ u_int w_level; struct witness *w_children[WITNESS_NCHILDREN]; }; @@ -838,11 +837,16 @@ p = CURPROC; if (flags & MTX_SPIN) { - if (!w->w_spin) + if ((w->w_typeflg & MTX_SPIN) == 0) 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)) { + if ((w->typeflg & MTX_RECURSE) == 0) + panic("mutex_enter: recursion on non-recursive" + " mutex %s @ %s:%d", m->mtx_description, + file, line); return; + } mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); i = PCPU_GET(witness_spin_check); if (i != 0 && w->w_level < i) { @@ -860,12 +864,17 @@ m->mtx_file = file; return; } - if (w->w_spin) + if (w->w_typeflg & MTX_SPIN) 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)) { + if ((w->typeflg & MTX_RECURSE) == 0) + panic("mutex_enter: recursion on non-recursive" + " mutex %s @ %s:%d", m->mtx_description, + file, line); return; + } if (witness_dead) goto out; if (cold) @@ -971,23 +980,33 @@ w = m->mtx_witness; if (flags & MTX_SPIN) { - if (!w->w_spin) + if ((w->w_typeflg & MTX_SPIN) == 0) 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)) { + if ((w->typeflg & MTX_RECURSE) == 0) + panic("mutex_exit: recursion on non-recursive" + " mutex %s @ %s:%d", m->mtx_description, + file, line); return; + } mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); PCPU_SET(witness_spin_check, PCPU_GET(witness_spin_check) & ~w->w_level); mtx_exit(&w_mtx, MTX_SPIN | MTX_QUIET); return; } - if (w->w_spin) + if (w->w_typeflg & MTX_SPIN) 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)) { + if ((w->typeflg & MTX_RECURSE) == 0) + panic("mutex_exit: recursion on non-recursive" + " mutex %s @ %s:%d", m->mtx_description, + file, line); return; + } if ((flags & MTX_NOSWITCH) == 0 && !mtx_legal2block() && !cold) panic("switchable mtx_exit() of %s when not legal @ %s:%d", @@ -1005,12 +1024,17 @@ if (panicstr) return; if (flags & MTX_SPIN) { - if (!w->w_spin) + if ((w->w_typeflg & MTX_SPIN) == 0) 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)) { + if ((w->w_typeflg & MTX_RECURSE) == 0) + panic("mutex_try_enter: recursion on" + " non-recursive mutex %s @ %s:%d", + m->mtx_description, file, line); return; + } mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); PCPU_SET(witness_spin_check, PCPU_GET(witness_spin_check) | w->w_level); @@ -1022,13 +1046,17 @@ return; } - if (w->w_spin) + if (w->w_typeflg & MTX_SPIN) 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)) { + if ((w->w_typeflg & MTX_RECURSE) == 0) + panic("mutex_try_enter: recursion on non-recursive" + " mutex %s @ %s:%d", m->mtx_description, file, + line); return; - + } w->w_file = file; w->w_line = line; m->mtx_line = line; @@ -1145,7 +1173,7 @@ w->w_description = description; mtx_exit(&w_mtx, MTX_SPIN | MTX_QUIET); if (flag & MTX_SPIN) { - w->w_spin = 1; + w->w_typeflg |= MTX_SPIN; i = 1; for (order = spin_order_list; *order != NULL; order++) { @@ -1157,6 +1185,9 @@ panic("spin lock %s not in order list", description); w->w_level = i; } + if (flag & MTX_RECURSE) + w->w_typeflg |= MTX_RECURSE; + return (w); } @@ -1270,10 +1301,10 @@ struct witness *w, *w1; for (w = w_all; w; w = w->w_next) - if (!w->w_spin) + if ((w->w_typeflg & MTX_SPIN) == 0) w->w_level = 0; for (w = w_all; w; w = w->w_next) { - if (w->w_spin) + if (w->w_typeflg & MTX_SPIN) continue; for (w1 = w_all; w1; w1 = w1->w_next) { if (isitmychild(w1, w)) diff -ru /cvs/sys_old/sys/mutex.h /usr/src/sys/sys/mutex.h --- /cvs/sys_old/sys/mutex.h Tue Jan 16 22:08:42 2001 +++ /usr/src/sys/sys/mutex.h Tue Jan 16 22:30:56 2001 @@ -67,7 +67,8 @@ #define MTX_SPIN 0x1 /* Spin only lock */ /* Options */ -#define MTX_RLIKELY 0x4 /* (opt) Recursion likely */ +#define MTX_RECURSE 0x2 /* Recursive lock (for mtx_init) */ +#define MTX_RLIKELY 0x4 /* 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 */ @@ -80,9 +81,9 @@ #define MTX_HARDOPTS (MTX_SPIN | MTX_FIRST | MTX_TOPHALF | MTX_NOSWITCH) /* Flags/value used in mtx_lock */ -#define MTX_RECURSE 0x01 /* (non-spin) lock held recursively */ +#define MTX_RECURSED 0x01 /* (non-spin) lock held recursively */ #define MTX_CONTESTED 0x02 /* (non-spin) lock contested */ -#define MTX_FLAGMASK ~(MTX_RECURSE | MTX_CONTESTED) +#define MTX_FLAGMASK ~(MTX_RECURSED | MTX_CONTESTED) #define MTX_UNOWNED 0x8 /* Cookie for free mutex */ #endif /* _KERNEL */ @@ -360,7 +361,7 @@ if (((mp)->mtx_lock & MTX_FLAGMASK) != ((uintptr_t)(tid)))\ mtx_enter_hard(mp, (type) & MTX_HARDOPTS, 0); \ else { \ - atomic_set_ptr(&(mp)->mtx_lock, MTX_RECURSE); \ + atomic_set_ptr(&(mp)->mtx_lock, MTX_RECURSED); \ (mp)->mtx_recurse++; \ } \ } \ @@ -408,10 +409,10 @@ */ #define _exitlock(mp, tid, type) do { \ if (!_release_lock(mp, tid)) { \ - if ((mp)->mtx_lock & MTX_RECURSE) { \ + if ((mp)->mtx_lock & MTX_RECURSED) { \ if (--((mp)->mtx_recurse) == 0) \ atomic_clear_ptr(&(mp)->mtx_lock, \ - MTX_RECURSE); \ + MTX_RECURSED); \ } else { \ mtx_exit_hard((mp), (type) & MTX_HARDOPTS); \ } \ @@ -422,7 +423,7 @@ #ifndef _exitlock_spin /* Release a spin lock (with possible recursion). */ #define _exitlock_spin(mp) do { \ - if ((mp)->mtx_recurse == 0) { \ + if (!mtx_recursed((mp))) { \ int _mtx_intr = (mp)->mtx_saveintr; \ \ _release_lock_quick(mp); \