Index: kern_sx.c =================================================================== RCS file: /usr/repo/src/sys/kern/kern_sx.c,v retrieving revision 1.54 diff -u -p -r1.54 kern_sx.c --- kern_sx.c 6 Jul 2007 13:20:44 -0000 1.54 +++ kern_sx.c 30 Sep 2007 22:11:16 -0000 @@ -217,15 +217,21 @@ _sx_try_slock(struct sx *sx, const char { uintptr_t x; +retry: x = sx->sx_lock; KASSERT(x != SX_LOCK_DESTROYED, ("sx_try_slock() of destroyed sx @ %s:%d", file, line)); - if ((x & SX_LOCK_SHARED) && atomic_cmpset_acq_ptr(&sx->sx_lock, x, - x + SX_ONE_SHARER)) { - LOCK_LOG_TRY("SLOCK", &sx->lock_object, 0, 1, file, line); - WITNESS_LOCK(&sx->lock_object, LOP_TRYLOCK, file, line); - curthread->td_locks++; - return (1); + if (x & SX_LOCK_SHARED) { + if (atomic_cmpset_acq_ptr(&sx->sx_lock, x, x + SX_ONE_SHARER)) { + LOCK_LOG_TRY("SLOCK", &sx->lock_object, 0, 1, file, line); + WITNESS_LOCK(&sx->lock_object, LOP_TRYLOCK, file, line); + curthread->td_locks++; + return (1); + } + /* + * Number of sharers may have changed, retry. + */ + goto retry; } LOCK_LOG_TRY("SLOCK", &sx->lock_object, 0, 0, file, line);