sched: enforce ref-counting on current task/thread pointers

This commit is contained in:
2026-04-01 18:17:05 +01:00
parent 15c2207ab9
commit 512356ac2d
28 changed files with 364 additions and 103 deletions
+19 -5
View File
@@ -282,7 +282,7 @@ struct task *task_from_tid(tid_t id)
void task_exit(int status)
{
struct task *self = current_task();
struct task *self = get_current_task();
unsigned long flags;
task_lock_irqsave(self, &flags);
struct task *parent = self->t_parent;
@@ -295,7 +295,7 @@ void task_exit(int status)
task_unlock(parent);
}
struct thread *cur_thread = current_thread();
struct thread *cur_thread = get_current_thread();
self->t_state = TASK_STOPPED;
cur_thread->tr_state = THREAD_STOPPED;
@@ -340,6 +340,9 @@ void task_exit(int status)
self->t_base.ob_refcount);
spin_unlock_irqrestore(handles_lock, flags);
put_current_thread(cur_thread);
put_current_task(self);
while (1) {
schedule(SCHED_NORMAL);
}
@@ -410,8 +413,19 @@ struct thread *task_create_thread(struct task *parent)
return thread;
}
struct task *current_task(void)
struct task *get_current_task(void)
{
struct thread *thr = current_thread();
return thr ? thr->tr_parent : NULL;
struct thread *thr = get_current_thread();
if (!thr) {
return NULL;
}
struct task *out = task_ref(thr->tr_parent);
put_current_thread(thr);
return out;
}
void put_current_task(struct task *task)
{
task_unref(task);
}