monitor: Correct preemptive locking
[bertos.git] / bertos / kern / proc.c
index 1d36ab0b16cdb482c65d894470d892e36f482a0d..32e3afe8a2f50b317af65291fa9f0d86fcc3f7b2 100644 (file)
@@ -145,7 +145,7 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi
 {
        Process *proc;
        size_t i;
-       size_t proc_size_words = ROUND2(sizeof(Process), sizeof(cpustack_t)) / sizeof(cpustack_t);
+       const size_t PROC_SIZE_WORDS = ROUND2(sizeof(Process), sizeof(cpustack_t)) / sizeof(cpustack_t);
 #if CONFIG_KERN_HEAP
        bool free_stack = false;
 #endif
@@ -184,13 +184,13 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi
        if (CPU_STACK_GROWS_UPWARD)
        {
                proc = (Process*)stack_base;
-               proc->stack = stack_base + proc_size_words;
+               proc->stack = stack_base + PROC_SIZE_WORDS;
                if (CPU_SP_ON_EMPTY_SLOT)
                        proc->stack++;
        }
        else
        {
-               proc = (Process*)(stack_base + stack_size / sizeof(cpustack_t) - proc_size_words);
+               proc = (Process*)(stack_base + stack_size / sizeof(cpustack_t) - PROC_SIZE_WORDS);
                proc->stack = (cpustack_t*)proc;
                if (CPU_SP_ON_EMPTY_SLOT)
                        proc->stack--;
@@ -199,11 +199,13 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi
        proc_init_struct(proc);
        proc->user_data = data;
 
-#if CONFIG_KERN_HEAP
+#if CONFIG_KERN_HEAP | CONFIG_KERN_MONITOR | (ARCH & ARCH_EMUL)
        proc->stack_base = stack_base;
        proc->stack_size = stack_size;
+       #if CONFIG_KERN_HEAP
        if (free_stack)
                proc->flags |= PF_FREESTACK;
+       #endif
 #endif
 
        /* Initialize process stack frame */
@@ -218,7 +220,7 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi
        ATOMIC(SCHED_ENQUEUE(proc));
 
 #if CONFIG_KERN_MONITOR
-       monitor_add(proc, name, stack_base, stack_size);
+       monitor_add(proc, name);
 #endif
 
        return proc;