timer: Amend previous commit (and Subversion sucks)
[bertos.git] / bertos / kern / proc.c
index bce8ac3e8a7fcadfd4eaf4d7073c659bf0813ff6..3f2548923dbc1527660cdf3138a091c285f00aee 100644 (file)
@@ -52,9 +52,6 @@
 
 #include <string.h>           /* memset() */
 
-#if CONFIG_KERN_PREEMPT
-#include "preempt.h"
-#endif
 
 /*
  * The scheduer tracks ready processes by enqueuing them in the
@@ -203,6 +200,15 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi
        #endif
 #endif
 
+#if CONFIG_KERN_PREEMPT
+       // FIXME: proc_exit
+       getcontext(&proc->context);
+       proc->context.uc_stack.ss_sp = stack_base;
+       proc->context.uc_stack.ss_size = stack_size;
+       proc->context.uc_link = NULL;
+       makecontext(&proc->context, (void (*)(void))proc_entry, 1, entry);
+
+#else // !CONFIG_KERN_PREEMPT
        /* Initialize process stack frame */
        CPU_PUSH_CALL_FRAME(proc->stack, proc_exit);
        CPU_PUSH_CALL_FRAME(proc->stack, entry);
@@ -214,6 +220,7 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi
        /* Add to ready list */
        ATOMIC(SCHED_ENQUEUE(proc));
        ATOMIC(LIST_ASSERT_VALID(&ProcReadyList));
+#endif // CONFIG_KERN_PREEMPT
 
 #if CONFIG_KERN_MONITOR
        monitor_add(proc, name);
@@ -238,7 +245,7 @@ void proc_rename(struct Process *proc, const char *name)
  */
 void proc_exit(void)
 {
-       TRACE;
+       TRACEMSG("%p:%s", CurrentProcess, CurrentProcess->monitor.name);
 
 #if CONFIG_KERN_MONITOR
        monitor_remove(CurrentProcess);