FreeBSD/sys/kern/kern_sx.c
/*
 * In the non-WITNESS case, sx_assert() can only detect that at least
 * *some* thread owns an slock, but it cannot guarantee that *this*
 * thread owns an slock.
 */
In the non-WITNESS case, sx_assert() can only detect that at least
*some* thread owns an slock, but it cannot guarantee that *this
thread owns an slock.
In the non - WITNESS case sx_assert () can only detect that at least * some * thread owns an slock but it cannot guarantee that * this thread owns an slock .
void
_sx_assert(const struct sx *sx, int what, const char *file, int line)
{
#ifndef WITNESS
	int slocked = 0;
#endif
	if (panicstr != NULL)
		return;
	switch (what) {
	case SA_SLOCKED:
	case SA_SLOCKED | SA_NOTRECURSED:
	case SA_SLOCKED | SA_RECURSED:
#ifndef WITNESS
		slocked = 1;
#endif
	case SA_LOCKED:
	case SA_LOCKED | SA_NOTRECURSED:
	case SA_LOCKED | SA_RECURSED:
#ifdef WITNESS
		witness_assert(&sx->lock_object, what, file, line);
#else
		if (sx->sx_lock == SX_LOCK_UNLOCKED ||
		    (!(sx->sx_lock & SX_LOCK_SHARED) && (slocked ||
		    sx_xholder(sx) != curthread)))
			panic("Lock %s not %slocked @ %s:%d\n",
			    sx->lock_object.lo_name, slocked ? "share " : "",
			    file, line);
		if (!(sx->sx_lock & SX_LOCK_SHARED)) {
			if (sx_recursed(sx)) {
				if (what & SA_NOTRECURSED)
					panic("Lock %s recursed @ %s:%d\n",
					    sx->lock_object.lo_name, file,
					    line);
			} else if (what & SA_RECURSED)
				panic("Lock %s not recursed @ %s:%d\n",
				    sx->lock_object.lo_name, file, line);
		}
#endif
		break;
	case SA_XLOCKED:
	case SA_XLOCKED | SA_NOTRECURSED:
	case SA_XLOCKED | SA_RECURSED:
		if (sx_xholder(sx) != curthread)
			panic("Lock %s not exclusively locked @ %s:%d\n",
			    sx->lock_object.lo_name, file, line);
		if (sx_recursed(sx)) {
			if (what & SA_NOTRECURSED)
				panic("Lock %s recursed @ %s:%d\n",
				    sx->lock_object.lo_name, file, line);
		} else if (what & SA_RECURSED)
			panic("Lock %s not recursed @ %s:%d\n",
			    sx->lock_object.lo_name, file, line);
		break;
	case SA_UNLOCKED:
#ifdef WITNESS
		witness_assert(&sx->lock_object, what, file, line);
#else
		if (sx_xholder(sx) == curthread)
			panic("Lock %s exclusively locked @ %s:%d\n",
			    sx->lock_object.lo_name, file, line);
#endif
		break;
	default:
		panic("Unknown sx lock assertion: %d @ %s:%d", what, file,
		    line);
	}
}
void _sx_assert ( const struct sx * sx , int what , const char * file , int line ) { #ifndef WITNESS int slocked = 0 ; #endif if ( panicstr != NULL ) return ; switch ( what ) { case SA_SLOCKED : case SA_SLOCKED | SA_NOTRECURSED : case SA_SLOCKED | SA_RECURSED : #ifndef WITNESS slocked = 1 ; #endif case SA_LOCKED : case SA_LOCKED | SA_NOTRECURSED : case SA_LOCKED | SA_RECURSED : #ifdef WITNESS witness_assert ( & sx -> lock_object , what , file , line ) ; #else if ( sx -> sx_lock == SX_LOCK_UNLOCKED || ( ! ( sx -> sx_lock & SX_LOCK_SHARED ) && ( slocked || sx_xholder ( sx ) != curthread ) ) ) panic ( " \n " , sx -> lock_object . lo_name , slocked ? " " : " " , file , line ) ; if ( ! ( sx -> sx_lock & SX_LOCK_SHARED ) ) { if ( sx_recursed ( sx ) ) { if ( what & SA_NOTRECURSED ) panic ( " \n " , sx -> lock_object . lo_name , file , line ) ; } else if ( what & SA_RECURSED ) panic ( " \n " , sx -> lock_object . lo_name , file , line ) ; } #endif break ; case SA_XLOCKED : case SA_XLOCKED | SA_NOTRECURSED : case SA_XLOCKED | SA_RECURSED : if ( sx_xholder ( sx ) != curthread ) panic ( " \n " , sx -> lock_object . lo_name , file , line ) ; if ( sx_recursed ( sx ) ) { if ( what & SA_NOTRECURSED ) panic ( " \n " , sx -> lock_object . lo_name , file , line ) ; } else if ( what & SA_RECURSED ) panic ( " \n " , sx -> lock_object . lo_name , file , line ) ; break ; case SA_UNLOCKED : #ifdef WITNESS witness_assert ( & sx -> lock_object , what , file , line ) ; #else if ( sx_xholder ( sx ) == curthread ) panic ( " \n " , sx -> lock_object . lo_name , file , line ) ; #endif break ; default : panic ( " " , what , file , line ) ; } }
In the non-WITNESS case, sx_assert() can only detect that at least
 *some* thread owns an slock, but it cannot guarantee that *this
 thread owns an slock.
In the non - WITNESS case sx_assert () can only detect that at least * some * thread owns an slock but it cannot guarantee that * this thread owns an slock .
/* FALLTHROUGH */ /*
		 * If some other thread has an exclusive lock or we
		 * have one and are asserting a shared lock, fail.
		 * Also, if no one has a lock at all, fail.
		 */ /*
		 * If we hold an exclusve lock fail.  We can't
		 * reliably check to see if we hold a shared lock or
		 * not.
		 */