summaryrefslogtreecommitdiff
path: root/src/kernel/task.c
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2020-09-13 19:51:09 -0400
committerBenji Dial <benji6283@gmail.com>2020-09-13 19:51:09 -0400
commit143156f63e2448733f1a35a74e629fe0ae9bb567 (patch)
treebcf70a6940038986da2cfb2d6ed380ed8ebb91de /src/kernel/task.c
parent54101cf327b7def90636babbadbb66ce697298ee (diff)
downloadportland-os-143156f63e2448733f1a35a74e629fe0ae9bb567.tar.gz
have command shell block while commands are running
Diffstat (limited to 'src/kernel/task.c')
-rw-r--r--src/kernel/task.c22
1 files changed, 17 insertions, 5 deletions
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