Merge pull request #1958 from Kijewski/sched_switch-on-run-queue

core: `sched_switch()` switch if not on runqueue
dev/timer
Ludwig Ortmann 9 years ago
commit ad14b60fe7

@ -114,11 +114,16 @@ int sched_run(void);
void sched_set_status(tcb_t *process, unsigned int status);
/**
* @brief Compare thread priorities and yield() (or set
* @ref sched_context_switch_request if inISR()) when @p other_prio is
* higher (has a lower value) than the current thread's priority
* @brief Yield if approriate.
*
* @param[in] other_prio The priority of the target thread
* @details Either yield if other_prio is higher than the current priority,
* or if the current thread is not on the runqueue.
*
* Depending on whether the current execution is in an ISR (inISR()),
* thread_yield_higher() is called or @ref sched_context_switch_request is set,
* respectively.
*
* @param[in] other_prio The priority of the target thread.
*/
void sched_switch(uint16_t other_prio);

@ -150,22 +150,27 @@ void sched_set_status(tcb_t *process, unsigned int status)
void sched_switch(uint16_t other_prio)
{
int in_isr = inISR();
tcb_t *active_thread = (tcb_t *) sched_active_thread;
uint16_t current_prio = active_thread->priority;
int on_runqueue = (active_thread->status >= STATUS_ON_RUNQUEUE);
DEBUG("sched_switch: active pid=%" PRIkernel_pid" prio=%" PRIu16
", other_prio=%" PRIu16 " in_isr=%i\n",
active_thread->pid, current_prio, other_prio, in_isr);
DEBUG("sched_switch: active pid=%" PRIkernel_pid" prio=%" PRIu16 " on_runqueue=%i "
", other_prio=%" PRIu16 "\n",
active_thread->pid, current_prio, on_runqueue, other_prio);
if (current_prio > other_prio) {
if (in_isr) {
if (!on_runqueue || (current_prio > other_prio)) {
if (inISR()) {
DEBUG("sched_switch: setting sched_context_switch_request.\n");
sched_context_switch_request = 1;
}
else {
DEBUG("sched_switch: yielding immediately.\n");
thread_yield_higher();
}
}
else {
DEBUG("sched_switch: continuing without yield.\n");
}
}
NORETURN void sched_task_exit(void)

Loading…
Cancel
Save