wip: thread and processes handle
This commit is contained in:
@ -2,34 +2,28 @@
|
||||
#include "debug.h"
|
||||
#include "interrupts.h"
|
||||
#include "kprintf.h"
|
||||
#include "task.h"
|
||||
#include "process.h"
|
||||
#include "thread.h"
|
||||
#include "time.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct task *current_task;
|
||||
struct pcb *current_pcb;
|
||||
struct tcb *current_tcb;
|
||||
|
||||
void scheduler(void)
|
||||
{
|
||||
// ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED
|
||||
void (*func[])(struct task *) = {
|
||||
zombify_task, NULL, NULL, NULL, NULL, remove_task, kfork,
|
||||
};
|
||||
|
||||
if (!current_task) // || current_task->next == current_task)
|
||||
return;
|
||||
cli();
|
||||
switch_pd(kernel_pd, (uint32_t *)((uint32_t)kernel_pd - HEAP_END));
|
||||
struct task *it = current_task->next;
|
||||
while (it && it->status != RUN) {
|
||||
if (it != current_task && func[it->status]) {
|
||||
struct task *new_it = it->prev;
|
||||
func[it->status](it);
|
||||
it = new_it;
|
||||
struct tcb *thread_to_switch;
|
||||
if (!current_tcb) {
|
||||
thread_to_switch = current_pcb->thread_list;
|
||||
} else {
|
||||
if (!current_tcb->next) {
|
||||
current_pcb = current_pcb->next;
|
||||
// TODO switch context
|
||||
thread_to_switch = current_pcb->thread_list;
|
||||
} else {
|
||||
thread_to_switch = current_tcb->next;
|
||||
}
|
||||
it = it->next;
|
||||
}
|
||||
switch_to_task(it);
|
||||
exec_signal_pending();
|
||||
toris();
|
||||
switch_thread(thread_to_switch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user