X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=kern%2Fproc.c;h=5290c2c5129d6095cf2d9a0aca2a9ce192123b1c;hb=139052d58a99cc47e0e2ac6b897a0c26a0105c2a;hp=fc3bfe81833ae6f11edff71df24eff0c621f08b3;hpb=efbdba7e2814415234ef47bd10ff888559ea90af;p=bertos.git diff --git a/kern/proc.c b/kern/proc.c index fc3bfe81..5290c2c5 100644 --- a/kern/proc.c +++ b/kern/proc.c @@ -49,6 +49,7 @@ #include #include #include +#include #include /* ARCH_EMUL */ #include /* ABS() */ @@ -109,6 +110,7 @@ static void proc_init_struct(Process *proc) #endif } +MOD_DEFINE(proc); void proc_init(void) { @@ -127,6 +129,7 @@ void proc_init(void) /* Make sure the assembly routine is up-to-date with us */ ASSERT(asm_switch_version() == 1); + MOD_INIT(proc); } @@ -149,14 +152,14 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi /* Ignore stack provided by caller and use the large enough default instead. */ stack_base = (cpustack_t *)LIST_HEAD(&StackFreeList); REMOVE(LIST_HEAD(&StackFreeList)); - stacksize = CONFIG_KERN_DEFSTACKSIZE; + stacksize = CONFIG_PROC_DEFSTACKSIZE; #elif CONFIG_KERN_HEAP /* Did the caller provide a stack for us? */ if (!stack_base) { /* Did the caller specify the desired stack size? */ if (!stacksize) - stacksize = CONFIG_KERN_DEFSTACKSIZE + sizeof(Process); + stacksize = CONFIG_PROC_DEFSTACKSIZE + sizeof(Process); /* Allocate stack dinamically */ if (!(stack_base = heap_alloc(stacksize))) @@ -240,12 +243,8 @@ void proc_rename(struct Process *proc, const char *name) */ void proc_schedule(void) { - /* This function must not have any "auto" variables, otherwise - * the compiler might put them on the stack of the process - * being switched out. - */ - static struct Process *old_process; - static cpuflags_t flags; + struct Process *old_process; + cpuflags_t flags; /* Remember old process to save its context later */ old_process = CurrentProcess; @@ -265,12 +264,18 @@ void proc_schedule(void) * are idle-spinning, we must allow interrupts, otherwise no * process will ever wake up. * + * During idle-spinning, can occur an interrupt, it may be able to + * 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; + CPU_MEMORY_BARRIER; IRQ_DISABLE; } IRQ_RESTORE(flags); @@ -281,7 +286,7 @@ void proc_schedule(void) */ if (CurrentProcess != old_process) { - static cpustack_t *dummy; + cpustack_t *dummy; #if CONFIG_KERN_PREEMPTIVE /* Reset quantum for this process */ @@ -328,7 +333,7 @@ void proc_exit(void) #warning This is wrong /* Reinsert process stack in free list */ ADDHEAD(&StackFreeList, (Node *)(CurrentProcess->stack - - (CONFIG_KERN_DEFSTACKSIZE / sizeof(cpustack_t)))); + - (CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)))); /* * NOTE: At this point the first two words of what used @@ -348,8 +353,7 @@ void proc_exit(void) */ void proc_switch(void) { - /* Just like proc_schedule, this function must not have auto variables. */ - static cpuflags_t flags; + cpuflags_t flags; IRQ_SAVE_DISABLE(flags); SCHED_ENQUEUE(CurrentProcess);