可以看到当前remaining_quantum 不等于0,就说明当前有更高优先级的thread抢占了当前的thread
所以讲当前thread 插在run queue的前面等下一次运行。
否则的话,就是当前thread时间片运行完,加到run queue的后面
void thread_preempt(void)
{
#if THREAD_CHECKS
ASSERT(current_thread->magic == THREAD_MAGIC);
ASSERT(current_thread->state == THREAD_RUNNING);
#endif
enter_critical_section();
#if THREAD_STATS
if (current_thread != idle_thread)
thread_stats.preempts++; /* only track when a meaningful preempt happens */
#endif
/* we are being preempted, so we get to go back into the front of the run queue if we have quantum left */
current_thread->state = THREAD_READY;
if (current_thread->remaining_quantum > 0)
insert_in_run_queue_head(current_thread);
else
insert_in_run_queue_tail(current_thread); /* if we're out of quantum, go to the tail of the queue */
thread_resched();
exit_critical_section();
}
所以讲当前thread 插在run queue的前面等下一次运行。
否则的话,就是当前thread时间片运行完,加到run queue的后面
void thread_preempt(void)
{
#if THREAD_CHECKS
ASSERT(current_thread->magic == THREAD_MAGIC);
ASSERT(current_thread->state == THREAD_RUNNING);
#endif
enter_critical_section();
#if THREAD_STATS
if (current_thread != idle_thread)
thread_stats.preempts++; /* only track when a meaningful preempt happens */
#endif
/* we are being preempted, so we get to go back into the front of the run queue if we have quantum left */
current_thread->state = THREAD_READY;
if (current_thread->remaining_quantum > 0)
insert_in_run_queue_head(current_thread);
else
insert_in_run_queue_tail(current_thread); /* if we're out of quantum, go to the tail of the queue */
thread_resched();
exit_critical_section();
}