FreeBSD/sys/kern/subr_sleepqueue.c
/*
 * Find the highest priority thread sleeping on a wait channel and resume it.
 */
Find the highest priority thread sleeping on a wait channel and resume it.
Find the highest priority thread sleeping on a wait channel and resume it .
int
sleepq_signal(void *wchan, int flags, int pri, int queue)
{
	struct sleepqueue *sq;
	struct thread *td, *besttd;
	int wakeup_swapper;
	CTR2(KTR_PROC, "sleepq_signal(%p, %d)", wchan, flags);
	KASSERT(wchan != NULL, ("%s: invalid NULL wait channel", __func__));
	MPASS((queue >= 0) && (queue < NR_SLEEPQS));
	sq = sleepq_lookup(wchan);
	if (sq == NULL)
		return (0);
	KASSERT(sq->sq_type == (flags & SLEEPQ_TYPE),
	    ("%s: mismatch between sleep/wakeup and cv_*", __func__));
	besttd = NULL;
	TAILQ_FOREACH(td, &sq->sq_blocked[queue], td_slpq) {
		if (besttd == NULL || td->td_priority < besttd->td_priority)
			besttd = td;
	}
	MPASS(besttd != NULL);
	thread_lock(besttd);
	wakeup_swapper = sleepq_resume_thread(sq, besttd, pri);
	thread_unlock(besttd);
	return (wakeup_swapper);
}
int sleepq_signal ( void * wchan , int flags , int pri , int queue ) { struct sleepqueue * sq ; struct thread * td , * besttd ; int wakeup_swapper ; CTR2 ( KTR_PROC , " " , wchan , flags ) ; KASSERT ( wchan != NULL , ( " " , __func__ ) ) ; MPASS ( ( queue >= 0 ) && ( queue < NR_SLEEPQS ) ) ; sq = sleepq_lookup ( wchan ) ; if ( sq == NULL ) return ( 0 ) ; KASSERT ( sq -> sq_type == ( flags & SLEEPQ_TYPE ) , ( " " , __func__ ) ) ; besttd = NULL ; TAILQ_FOREACH ( td , & sq -> sq_blocked [ queue ] , td_slpq ) { if ( besttd == NULL || td -> td_priority < besttd -> td_priority ) besttd = td ; } MPASS ( besttd != NULL ) ; thread_lock ( besttd ) ; wakeup_swapper = sleepq_resume_thread ( sq , besttd , pri ) ; thread_unlock ( besttd ) ; return ( wakeup_swapper ) ; }
Find the highest priority thread sleeping on a wait channel and resume it.
Find the highest priority thread sleeping on a wait channel and resume it .
/*
	 * Find the highest priority thread on the queue.  If there is a
	 * tie, use the thread that first appears in the queue as it has
	 * been sleeping the longest since threads are always added to
	 * the tail of sleep queues.
	 */