FreeBSD/sys/kern/kern_sx.c
/*
 * Try to do a non-blocking upgrade from a shared lock to an exclusive lock.
 * This will only succeed if this thread holds a single shared lock.
 * Return 1 if if the upgrade succeed, 0 otherwise.
 */
Try to do a non-blocking upgrade from a shared lock to an exclusive lock.
This will only succeed if this thread holds a single shared lock.
Return 1 if if the upgrade succeed, 0 otherwise.
Try to do a non - blocking upgrade from a shared lock to an exclusive lock . This will only succeed if this thread holds a single shared lock . Return 1 if if the upgrade succeed 0 otherwise .
int
sx_try_upgrade_(struct sx *sx, const char *file, int line)
{
	uintptr_t x;
	int success;
	if (SCHEDULER_STOPPED())
		return (1);
	KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
	    ("sx_try_upgrade() of destroyed sx @ %s:%d", file, line));
	_sx_assert(sx, SA_SLOCKED, file, line);
	x = sx->sx_lock & SX_LOCK_EXCLUSIVE_WAITERS;
	success = atomic_cmpset_ptr(&sx->sx_lock, SX_SHARERS_LOCK(1) | x,
	    (uintptr_t)curthread | x);
	LOCK_LOG_TRY("XUPGRADE", &sx->lock_object, 0, success, file, line);
	if (success) {
		WITNESS_UPGRADE(&sx->lock_object, LOP_EXCLUSIVE | LOP_TRYLOCK,
		    file, line);
		LOCKSTAT_RECORD0(sx__upgrade, sx);
	}
	return (success);
}
int sx_try_upgrade_ ( struct sx * sx , const char * file , int line ) { uintptr_t x ; int success ; if ( SCHEDULER_STOPPED ( ) ) return ( 1 ) ; KASSERT ( sx -> sx_lock != SX_LOCK_DESTROYED , ( " " , file , line ) ) ; _sx_assert ( sx , SA_SLOCKED , file , line ) ; x = sx -> sx_lock & SX_LOCK_EXCLUSIVE_WAITERS ; success = atomic_cmpset_ptr ( & sx -> sx_lock , SX_SHARERS_LOCK ( 1 ) | x , ( uintptr_t ) curthread | x ) ; LOCK_LOG_TRY ( " " , & sx -> lock_object , 0 , success , file , line ) ; if ( success ) { WITNESS_UPGRADE ( & sx -> lock_object , LOP_EXCLUSIVE | LOP_TRYLOCK , file , line ) ; LOCKSTAT_RECORD0 ( sx__upgrade , sx ) ; } return ( success ) ; }
Try to do a non-blocking upgrade from a shared lock to an exclusive lock.
Try to do a non - blocking upgrade from a shared lock to an exclusive lock .
/*
	 * Try to switch from one shared lock to an exclusive lock.  We need
	 * to maintain the SX_LOCK_EXCLUSIVE_WAITERS flag if set so that
	 * we will wake up the exclusive waiters when we drop the lock.
	 */