- struct Process *old_process;
- cpuflags_t flags;
-
- ATOMIC(LIST_ASSERT_VALID(&ProcReadyList));
- ASSERT_USER_CONTEXT();
- ASSERT_IRQ_ENABLED();
-
- /* Remember old process to save its context later */
- old_process = CurrentProcess;
-
- /* Poll on the ready queue for the first ready process */
- IRQ_SAVE_DISABLE(flags);
- while (!(CurrentProcess = (struct Process *)list_remHead(&ProcReadyList)))
- {
- /*
- * Make sure we physically reenable interrupts here, no matter what
- * the current task status is. This is important because if we
- * are idle-spinning, we must allow interrupts, otherwise no
- * process will ever wake up.
- *
- * During idle-spinning, an interrupt can occur and it may
- * modify \p ProcReadyList. To ensure that compiler reload this
- * variable every while cycle we call CPU_MEMORY_BARRIER.
- * The memory barrier ensure that all variables used in this context
- * are reloaded.
- * \todo If there was a way to write sig_wait() so that it does not
- * disable interrupts while waiting, there would not be any
- * reason to do this.
- */
- IRQ_ENABLE;
- CPU_IDLE;
- MEMORY_BARRIER;
- IRQ_DISABLE;
- }
- IRQ_RESTORE(flags);