FreeBSD/sys/kern/kern_rwlock.c
/*
 * In the non-WITNESS case, rw_assert() can only detect that at least
 * *some* thread owns an rlock, but it cannot guarantee that *this*
 * thread owns an rlock.
 */
In the non-WITNESS case, rw_assert() can only detect that at least
*some* thread owns an rlock, but it cannot guarantee that *this
thread owns an rlock.
In the non - WITNESS case rw_assert () can only detect that at least * some * thread owns an rlock but it cannot guarantee that * this thread owns an rlock .
void
__rw_assert(const volatile uintptr_t *c, int what, const char *file, int line)
{
	const struct rwlock *rw;
	if (panicstr != NULL)
		return;
	rw = rwlock2rw(c);
	switch (what) {
	case RA_LOCKED:
	case RA_LOCKED | RA_RECURSED:
	case RA_LOCKED | RA_NOTRECURSED:
	case RA_RLOCKED:
	case RA_RLOCKED | RA_RECURSED:
	case RA_RLOCKED | RA_NOTRECURSED:
#ifdef WITNESS
		witness_assert(&rw->lock_object, what, file, line);
#else
		if (rw->rw_lock == RW_UNLOCKED ||
		    (!(rw->rw_lock & RW_LOCK_READ) && (what & RA_RLOCKED ||
		    rw_wowner(rw) != curthread)))
			panic("Lock %s not %slocked @ %s:%d\n",
			    rw->lock_object.lo_name, (what & RA_RLOCKED) ?
			    "read " : "", file, line);
		if (!(rw->rw_lock & RW_LOCK_READ) && !(what & RA_RLOCKED)) {
			if (rw_recursed(rw)) {
				if (what & RA_NOTRECURSED)
					panic("Lock %s recursed @ %s:%d\n",
					    rw->lock_object.lo_name, file,
					    line);
			} else if (what & RA_RECURSED)
				panic("Lock %s not recursed @ %s:%d\n",
				    rw->lock_object.lo_name, file, line);
		}
#endif
		break;
	case RA_WLOCKED:
	case RA_WLOCKED | RA_RECURSED:
	case RA_WLOCKED | RA_NOTRECURSED:
		if (rw_wowner(rw) != curthread)
			panic("Lock %s not exclusively locked @ %s:%d\n",
			    rw->lock_object.lo_name, file, line);
		if (rw_recursed(rw)) {
			if (what & RA_NOTRECURSED)
				panic("Lock %s recursed @ %s:%d\n",
				    rw->lock_object.lo_name, file, line);
		} else if (what & RA_RECURSED)
			panic("Lock %s not recursed @ %s:%d\n",
			    rw->lock_object.lo_name, file, line);
		break;
	case RA_UNLOCKED:
#ifdef WITNESS
		witness_assert(&rw->lock_object, what, file, line);
#else
		if (rw_wowner(rw) == curthread)
			panic("Lock %s exclusively locked @ %s:%d\n",
			    rw->lock_object.lo_name, file, line);
#endif
		break;
	default:
		panic("Unknown rw lock assertion: %d @ %s:%d", what, file,
		    line);
	}
}
void __rw_assert ( const volatile uintptr_t * c , int what , const char * file , int line ) { const struct rwlock * rw ; if ( panicstr != NULL ) return ; rw = rwlock2rw ( c ) ; switch ( what ) { case RA_LOCKED : case RA_LOCKED | RA_RECURSED : case RA_LOCKED | RA_NOTRECURSED : case RA_RLOCKED : case RA_RLOCKED | RA_RECURSED : case RA_RLOCKED | RA_NOTRECURSED : #ifdef WITNESS witness_assert ( & rw -> lock_object , what , file , line ) ; #else if ( rw -> rw_lock == RW_UNLOCKED || ( ! ( rw -> rw_lock & RW_LOCK_READ ) && ( what & RA_RLOCKED || rw_wowner ( rw ) != curthread ) ) ) panic ( " \n " , rw -> lock_object . lo_name , ( what & RA_RLOCKED ) ? " " : " " , file , line ) ; if ( ! ( rw -> rw_lock & RW_LOCK_READ ) && ! ( what & RA_RLOCKED ) ) { if ( rw_recursed ( rw ) ) { if ( what & RA_NOTRECURSED ) panic ( " \n " , rw -> lock_object . lo_name , file , line ) ; } else if ( what & RA_RECURSED ) panic ( " \n " , rw -> lock_object . lo_name , file , line ) ; } #endif break ; case RA_WLOCKED : case RA_WLOCKED | RA_RECURSED : case RA_WLOCKED | RA_NOTRECURSED : if ( rw_wowner ( rw ) != curthread ) panic ( " \n " , rw -> lock_object . lo_name , file , line ) ; if ( rw_recursed ( rw ) ) { if ( what & RA_NOTRECURSED ) panic ( " \n " , rw -> lock_object . lo_name , file , line ) ; } else if ( what & RA_RECURSED ) panic ( " \n " , rw -> lock_object . lo_name , file , line ) ; break ; case RA_UNLOCKED : #ifdef WITNESS witness_assert ( & rw -> lock_object , what , file , line ) ; #else if ( rw_wowner ( rw ) == curthread ) panic ( " \n " , rw -> lock_object . lo_name , file , line ) ; #endif break ; default : panic ( " " , what , file , line ) ; } }
In the non-WITNESS case, rw_assert() can only detect that at least
 *some* thread owns an rlock, but it cannot guarantee that *this
 thread owns an rlock.
In the non - WITNESS case rw_assert () can only detect that at least * some * thread owns an rlock but it cannot guarantee that * this thread owns an rlock .
/*
		 * If some other thread has a write lock or we have one
		 * and are asserting a read lock, fail.  Also, if no one
		 * has a lock at all, fail.
		 */ /*
		 * If we hold a write lock fail.  We can't reliably check
		 * to see if we hold a read lock or not.
		 */