FreeBSD/sys/kern/sched_ule.c
/*
 * Sets the thread lock and ts_cpu to match the requested cpu.  Unlocks the
 * current lock and returns with the assigned queue locked.
 */
Sets the thread lock and ts_cpu to match the requested cpu.  Unlocks the
current lock and returns with the assigned queue locked.
Sets the thread lock and ts_cpu to match the requested cpu . Unlocks the current lock and returns with the assigned queue locked .
static inline struct tdq *
sched_setcpu(struct thread *td, int cpu, int flags)
{
	struct tdq *tdq;
	THREAD_LOCK_ASSERT(td, MA_OWNED);
	tdq = TDQ_CPU(cpu);
	td_get_sched(td)->ts_cpu = cpu;
	if (td->td_lock == TDQ_LOCKPTR(tdq))
		return (tdq);
#ifdef notyet
	if (TD_CAN_RUN(td)) {
		TDQ_LOCK(tdq);
		thread_lock_set(td, TDQ_LOCKPTR(tdq));
		return (tdq);
	}
#endif
	spinlock_enter();
	thread_lock_block(td);
	TDQ_LOCK(tdq);
	thread_lock_unblock(td, TDQ_LOCKPTR(tdq));
	spinlock_exit();
	return (tdq);
}
static inline struct tdq * sched_setcpu ( struct thread * td , int cpu , int flags ) { struct tdq * tdq ; THREAD_LOCK_ASSERT ( td , MA_OWNED ) ; tdq = TDQ_CPU ( cpu ) ; td_get_sched ( td ) -> ts_cpu = cpu ; if ( td -> td_lock == TDQ_LOCKPTR ( tdq ) ) return ( tdq ) ; #ifdef notyet if ( TD_CAN_RUN ( td ) ) { TDQ_LOCK ( tdq ) ; thread_lock_set ( td , TDQ_LOCKPTR ( tdq ) ) ; return ( tdq ) ; } #endif spinlock_enter ( ) ; thread_lock_block ( td ) ; TDQ_LOCK ( tdq ) ; thread_lock_unblock ( td , TDQ_LOCKPTR ( tdq ) ) ; spinlock_exit ( ) ; return ( tdq ) ; }
Sets the thread lock and ts_cpu to match the requested cpu.
Sets the thread lock and ts_cpu to match the requested cpu .
/*
	 * If the lock matches just return the queue.
	 */ /*
	 * If the thread isn't running its lockptr is a
	 * turnstile or a sleepqueue.  We can just lock_set without
	 * blocking.
	 */ /*
	 * The hard case, migration, we need to block the thread first to
	 * prevent order reversals with other cpus locks.
	 */