FreeBSD/sys/kern/kern_umtx.c
/*
 * Check if the mutex is available and wake up a waiter,
 * only for simple mutex.
 */
Check if the mutex is available and wake up a waiter,
only for simple mutex.
Check if the mutex is available and wake up a waiter only for simple mutex .
static int
do_wake_umutex(struct thread *td, struct umutex *m)
{
	struct umtx_key key;
	uint32_t owner;
	uint32_t flags;
	int error;
	int count;
	error = fueword32(&m->m_owner, &owner);
	if (error == -1)
		return (EFAULT);
	if ((owner & ~UMUTEX_CONTESTED) != 0 && owner != UMUTEX_RB_OWNERDEAD &&
	    owner != UMUTEX_RB_NOTRECOV)
		return (0);
	error = fueword32(&m->m_flags, &flags);
	if (error == -1)
		return (EFAULT);
	if ((error = umtx_key_get(m, TYPE_NORMAL_UMUTEX, GET_SHARE(flags),
	    &key)) != 0)
		return (error);
	umtxq_lock(&key);
	umtxq_busy(&key);
	count = umtxq_count(&key);
	umtxq_unlock(&key);
	if (count <= 1 && owner != UMUTEX_RB_OWNERDEAD &&
	    owner != UMUTEX_RB_NOTRECOV) {
		error = casueword32(&m->m_owner, UMUTEX_CONTESTED, &owner,
		    UMUTEX_UNOWNED);
		if (error == -1)
			error = EFAULT;
	}
	umtxq_lock(&key);
	if (error == 0 && count != 0 && ((owner & ~UMUTEX_CONTESTED) == 0 ||
	    owner == UMUTEX_RB_OWNERDEAD || owner == UMUTEX_RB_NOTRECOV))
		umtxq_signal(&key, 1);
	umtxq_unbusy(&key);
	umtxq_unlock(&key);
	umtx_key_release(&key);
	return (error);
}
static int do_wake_umutex ( struct thread * td , struct umutex * m ) { struct umtx_key key ; uint32_t owner ; uint32_t flags ; int error ; int count ; error = fueword32 ( & m -> m_owner , & owner ) ; if ( error == -1 ) return ( EFAULT ) ; if ( ( owner & ~ UMUTEX_CONTESTED ) != 0 && owner != UMUTEX_RB_OWNERDEAD && owner != UMUTEX_RB_NOTRECOV ) return ( 0 ) ; error = fueword32 ( & m -> m_flags , & flags ) ; if ( error == -1 ) return ( EFAULT ) ; if ( ( error = umtx_key_get ( m , TYPE_NORMAL_UMUTEX , GET_SHARE ( flags ) , & key ) ) != 0 ) return ( error ) ; umtxq_lock ( & key ) ; umtxq_busy ( & key ) ; count = umtxq_count ( & key ) ; umtxq_unlock ( & key ) ; if ( count <= 1 && owner != UMUTEX_RB_OWNERDEAD && owner != UMUTEX_RB_NOTRECOV ) { error = casueword32 ( & m -> m_owner , UMUTEX_CONTESTED , & owner , UMUTEX_UNOWNED ) ; if ( error == -1 ) error = EFAULT ; } umtxq_lock ( & key ) ; if ( error == 0 && count != 0 && ( ( owner & ~ UMUTEX_CONTESTED ) == 0 || owner == UMUTEX_RB_OWNERDEAD || owner == UMUTEX_RB_NOTRECOV ) ) umtxq_signal ( & key , 1 ) ; umtxq_unbusy ( & key ) ; umtxq_unlock ( & key ) ; umtx_key_release ( & key ) ; return ( error ) ; }
Check if the mutex is available and wake up a waiter,
 only for simple mutex.
Check if the mutex is available and wake up a waiter only for simple mutex .
/* We should only ever be in here for contested locks */