aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/tasks
diff options
context:
space:
mode:
authorMarvin Borner2020-05-12 23:53:02 +0200
committerMarvin Borner2020-05-12 23:53:02 +0200
commit3624343800de35b9058c11186dc02dd20d98aedf (patch)
treedb9e2408a3d440bcc02f4b7e12ef597642fdaafc /src/kernel/tasks
parent3b16ca421aad772e0f40716e2fc66215d322f7f7 (diff)
Added scheduler spinlocking
I don't think it's needed though, ints are disabled anyway
Diffstat (limited to 'src/kernel/tasks')
-rw-r--r--src/kernel/tasks/process.c11
-rw-r--r--src/kernel/tasks/userspace.c5
2 files changed, 10 insertions, 6 deletions
diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c
index 45c9937..ebb7a81 100644
--- a/src/kernel/tasks/process.c
+++ b/src/kernel/tasks/process.c
@@ -22,11 +22,15 @@ extern u32 stack_hold;
void scheduler(struct regs *regs)
{
+ static int locked = 0;
+ spinlock(&locked);
+
serial_put('.');
if (quantum == 0 || current_proc->state != PROC_RUNNING) {
quantum = 42; // For next process
} else {
quantum--;
+ locked = 0;
return;
}
@@ -45,13 +49,14 @@ void scheduler(struct regs *regs)
while (current_proc->state == PROC_ASLEEP) {
current_proc = current_proc->next;
if (current_proc == NULL) {
- //warn("No next process!");
+ warn("No next process!");
current_proc = root;
}
}
memcpy(regs, &current_proc->registers, sizeof(struct regs));
paging_switch_directory(current_proc->cr3);
+ locked = 0;
}
void process_force_switch()
@@ -66,7 +71,7 @@ void process_init(struct process *proc)
log("Initializing process %d", pid);
root = proc;
root->pid = pid++;
- root->next = NULL;
+ root->next = proc;
root->state = PROC_RUNNING;
current_proc = root;
@@ -85,6 +90,8 @@ void process_print_tree()
info("%s with PID %d (state: %s)", proc->name, proc->pid,
proc->state == PROC_RUNNING ? "running" : "sleeping");
proc = proc->next;
+ if (proc->pid == 1)
+ break;
}
serial_put('\n');
}
diff --git a/src/kernel/tasks/userspace.c b/src/kernel/tasks/userspace.c
index e9fd2f0..3164965 100644
--- a/src/kernel/tasks/userspace.c
+++ b/src/kernel/tasks/userspace.c
@@ -22,14 +22,11 @@ u32 spawn_child(struct process *child)
void userspace_enter(struct process *proc)
{
proc_bottom = proc;
- proc->next = NULL;
hl_eip = proc->registers.eip;
hl_esp = proc->registers.esp;
paging_switch_directory(proc->cr3);
- current_proc = proc;
-
- debug("Jumping to userspace!");
+ //debug("Jumping to userspace!");
jump_userspace();
}