X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fproc.c;h=a18fc40498d52e85e198ee54e5e13a1e90e2c49e;hb=d1b1e979862ca866eaee324e0363d57bf5a0e13b;hp=713c457f9c701820cf8d32a26e11d9d719b926db;hpb=8203999c6575e646b16363b40eaca03c6ea4f447;p=bertos.git diff --git a/bertos/kern/proc.c b/bertos/kern/proc.c index 713c457f..a18fc404 100644 --- a/bertos/kern/proc.c +++ b/bertos/kern/proc.c @@ -139,11 +139,6 @@ void proc_init(void) monitor_init(); monitor_add(current_process, "main"); #endif - -#if CONFIG_KERN_PREEMPT - preempt_init(); -#endif - MOD_INIT(proc); } @@ -425,11 +420,41 @@ void proc_exit(void) ASSERT(0); } - /** - * Get the pointer to the user data of the current process + * Call the scheduler and eventually replace the current running process. */ -iptr_t proc_currentUserData(void) +void proc_schedule(void) { - return current_process->user_data; + Process *old_process = current_process; + + IRQ_ASSERT_DISABLED(); + + /* Poll on the ready queue for the first ready process */ + LIST_ASSERT_VALID(&proc_ready_list); + while (!(current_process = (struct Process *)list_remHead(&proc_ready_list))) + { + /* + * 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 proc_ready_list. 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; + } + if (CONTEXT_SWITCH_FROM_ISR()) + proc_switchTo(current_process, old_process); + /* This RET resumes the execution on the new process */ + LOG_INFO("resuming %p:%s\n", current_process, proc_currentName()); }