summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2026-05-22 00:11:54 +0000
committerAda Christine <adachristine18@gmail.com>2026-05-22 00:11:54 +0000
commitbb16bd0a71a8e615441694b97813cda2f8ea8ff8 (patch)
treeea9b83d16d110dd40e7120baa829a3793fbecd25
parentedc42358664e9d70227e274273321ab032394a7e (diff)
thread termination cleanup
-rw-r--r--kc/core/arch_thread.c7
-rw-r--r--kc/core/task.c27
-rw-r--r--kc/core/task.h3
3 files changed, 31 insertions, 6 deletions
diff --git a/kc/core/arch_thread.c b/kc/core/arch_thread.c
index 8f5f8d3..19e8908 100644
--- a/kc/core/arch_thread.c
+++ b/kc/core/arch_thread.c
@@ -73,12 +73,9 @@ void *arch_idle_loop(void *)
return nullptr;
}
-noreturn void arch_terminate_thread(void *result, struct kc_thread *thread)
+noreturn void arch_terminate_thread(union kc_thread_result result, struct kc_thread *)
{
- thread->result = (union kc_thread_result){ .pointer = result };
- thread->status = TERMINATED;
- thread->kernel_stack_pointer = thread->kernel_stack_head;
- task_schedule();
+ kct_terminate(result);
for (;;) __asm__ ("hlt");
}
diff --git a/kc/core/task.c b/kc/core/task.c
index aa5d179..0f2149d 100644
--- a/kc/core/task.c
+++ b/kc/core/task.c
@@ -384,3 +384,30 @@ static int sleeping_thread_callback(uint64_t nanoseconds)
return 0;
}
+
+typedef void (locked_scheduler_action)(void *);
+
+static void with_locked_scheduler(
+ locked_scheduler_action *action,
+ void *action_parameter)
+{
+ lock_scheduler();
+ action(action_parameter);
+ unlock_scheduler();
+}
+
+static void terminate_action(void *result)
+{
+ union kc_thread_result *result_value = result;
+ current_thread->result = *result_value;
+ current_thread->kernel_stack_pointer = current_thread->kernel_stack_head;
+ // TODO: wake threads waiting
+ // TODO: write waitng thread code
+ //
+}
+
+void kct_terminate(union kc_thread_result result)
+{
+ with_locked_scheduler(terminate_action, &result);
+}
+
diff --git a/kc/core/task.h b/kc/core/task.h
index e5e9d92..eae38bb 100644
--- a/kc/core/task.h
+++ b/kc/core/task.h
@@ -31,5 +31,6 @@ struct kc_thread
};
void task_init(void);
-void task_schedule(void);
+
+void kct_terminate(union kc_thread_result result);