40 lines
999 B
C
40 lines
999 B
C
#include "kernel.h"
|
|
#include "process.h"
|
|
|
|
extern struct process_t* processes_list;
|
|
extern struct process_t* current_process;
|
|
|
|
void scheduler_init()
|
|
{
|
|
// Choose first process?
|
|
current_process = processes_list;
|
|
}
|
|
|
|
struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context)
|
|
{
|
|
current_process->context = context;
|
|
current_process->status = READY;
|
|
|
|
for (;;) {
|
|
struct process_t* prev_process = current_process;
|
|
if (current_process->next != NULL)
|
|
{
|
|
current_process = current_process->next;
|
|
} else
|
|
{
|
|
current_process = processes_list;
|
|
}
|
|
|
|
if (current_process != NULL && current_process->status == DEAD)
|
|
{
|
|
process_delete(&prev_process, current_process);
|
|
} else
|
|
{
|
|
current_process->status = RUNNING;
|
|
break;
|
|
}
|
|
}
|
|
|
|
DEBUG("SCHEDULER CALLED: current_process=%p", current_process);
|
|
return current_process->context;
|
|
} |