From 143156f63e2448733f1a35a74e629fe0ae9bb567 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 13 Sep 2020 19:51:09 -0400 Subject: have command shell block while commands are running --- src/kernel/task.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/kernel/task.c') diff --git a/src/kernel/task.c b/src/kernel/task.c index 6c53510..942d1c4 100644 --- a/src/kernel/task.c +++ b/src/kernel/task.c @@ -64,11 +64,11 @@ void init_tasks() { : : : "ax"); } -void new_task(struct task_state state) { +uint32_t new_task(struct task_state state) { for (uint8_t n = 0; n < MAX_TASKS; ++n) if (!tasks[n].page_directory) { tasks[n] = state; - return; + return n + 1; } PANIC("Maximum number of tasks reached."); } @@ -77,15 +77,20 @@ void advance_active_task() { do if (++active_task == tasks + MAX_TASKS) active_task = tasks; - while (!active_task->page_directory); + while (!active_task->page_directory || active_task->wait_mode); } void make_sure_tasks() { for (uint8_t n = 0; n < MAX_TASKS; ++n) if (tasks[n].page_directory) - return; + while (1) { + for (uint8_t n = 0; n < MAX_TASKS; ++n) + if (tasks[n].page_directory && !tasks[n].wait_mode) + return; + asm ("hlt"); + } set_log_mode(LOG_SYSTEM); - logsz("No active tasks, halting."); + logsz("No tasks, halting."); while (1) asm ("hlt"); } @@ -95,4 +100,11 @@ void delete_task(struct task_state *state) { free_task_pd(state->page_directory); switch_to_task_cr3(); state->page_directory = 0; + + uint32_t handle = state - tasks + 1; + for (uint8_t n = 0; n < MAX_TASKS; ++n) + if (tasks[n].page_directory && + (tasks[n].wait_mode == PROCESS_END) && + (tasks[n].wait_arg == handle)) + tasks[n].wait_mode = NONE; } \ No newline at end of file -- cgit v1.2.3