ATOMIC(LIST_ASSERT_VALID(&ProcReadyList));
+ TRACEMSG("hello1");
IRQ_DISABLE;
/* Poll on the ready queue for the first ready process */
while (!(CurrentProcess = (struct Process *)list_remHead(&ProcReadyList)))
{
+ TRACEMSG("hello2");
/*
* Make sure we physically reenable interrupts here, no matter what
* the current task status is. This is important because if we
* are reloaded.
*/
IRQ_ENABLE;
- CPU_IDLE;
+ //FIXME: calls Qt stuff from sighandler! CPU_IDLE;
MEMORY_BARRIER;
IRQ_DISABLE;
+ TRACEMSG("hello3");
}
IRQ_ENABLE;
+ TRACEMSG("hello4");
}
void proc_preempt_timer(void)
// TODO: check Quantum
alarm(1);
- ATOMIC(SCHED_ENQUEUE(CurrentProcess));
- proc_schedule();
+
+ if (CurrentProcess)
+ {
+ TRACEMSG("preempting %p:%s", CurrentProcess, CurrentProcess->monitor.name);
+ ATOMIC(SCHED_ENQUEUE(CurrentProcess));
+ proc_schedule();
+ }
}
void proc_schedule(void)
{
+ TRACE;
+
+ // Will invoke proc_preempt() in interrupt context
kill(0, SIGUSR1);
}
proc_schedule();
}
+void proc_entry(void (*user_entry)(void))
+{
+ user_entry();
+ proc_exit();
+}
+
/* signal handler */
void irq_entry(int signum)
{
Process *old_process;
- TRACEMSG("storing %p:%s", CurrentProcess, CurrentProcess->monitor.name);
- CurrentProcess->leaving = false;
- getcontext(&CurrentProcess->context);
+// TRACEMSG("storing %p:%s", CurrentProcess, CurrentProcess->monitor.name);
+// CurrentProcess->leaving = false;
+// getcontext(&CurrentProcess->context);
/* We get here in two ways: directly, and after setcontext() below */
- if (CurrentProcess->leaving)
- {
- TRACEMSG("leaving to %p:%s", CurrentProcess, CurrentProcess->monitor.name);
- return;
- }
+// if (CurrentProcess->leaving)
+// {
+// TRACEMSG("leaving to %p:%s", CurrentProcess, CurrentProcess->monitor.name);
+// return;
+// }
old_process = CurrentProcess;
if (old_process != CurrentProcess)
{
- TRACEMSG("launching %p:%s", CurrentProcess, CurrentProcess->monitor.name);
- CurrentProcess->leaving = true;
- setcontext(&CurrentProcess->context);
+ TRACEMSG("switching from %p:%s to %p:%s",
+ old_process, old_process->monitor.name,
+ CurrentProcess, CurrentProcess->monitor.name);
+ swapcontext(&old_process->context, &CurrentProcess->context);
+// TRACEMSG("launching %p:%s", CurrentProcess, CurrentProcess->monitor.name);
+// CurrentProcess->leaving = true;
+// setcontext(&CurrentProcess->context);
/* not reached */
}
#include <string.h> /* memset() */
-#if CONFIG_KERN_PREEMPT
-#include "preempt.h"
-#endif
/*
* The scheduer tracks ready processes by enqueuing them in the
proc->context.uc_stack.ss_sp = stack_base;
proc->context.uc_stack.ss_size = stack_size;
proc->context.uc_link = NULL;
- makecontext(&proc->context, entry, 0);
+ makecontext(&proc->context, (void (*)(void))proc_entry, 1, entry);
#else // !CONFIG_KERN_PREEMPT
/* Initialize process stack frame */
*/
void proc_exit(void)
{
- TRACE;
+ TRACEMSG("%p:%s", CurrentProcess, CurrentProcess->monitor.name);
#if CONFIG_KERN_MONITOR
monitor_remove(CurrentProcess);