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
+15 -3
View File
@@ -105,7 +105,7 @@ void thread_free(struct thread *thr)
{
}
struct thread *current_thread(void)
struct thread *get_current_thread(void)
{
struct cpu_data *cpu = get_this_cpu();
if (!cpu) {
@@ -113,13 +113,24 @@ struct thread *current_thread(void)
}
struct thread *out = cpu->c_rq.rq_cur;
object_ref(&out->tr_base);
put_cpu(cpu);
return out;
}
void put_current_thread(struct thread *thr)
{
object_unref(&thr->tr_base);
}
bool need_resched(void)
{
return (current_thread()->tr_flags & THREAD_F_NEED_RESCHED) != 0;
struct thread *thr = get_current_thread();
bool result = (thr->tr_flags & THREAD_F_NEED_RESCHED) != 0;
put_current_thread(thr);
return result;
}
int thread_priority(struct thread *thr)
@@ -143,7 +154,7 @@ void thread_awaken(struct thread *thr)
void thread_exit(void)
{
struct thread *self = current_thread();
struct thread *self = get_current_thread();
unsigned long flags;
thread_lock_irqsave(self, &flags);
self->tr_state = THREAD_STOPPED;
@@ -153,6 +164,7 @@ void thread_exit(void)
self->tr_parent->t_id,
self->tr_id);
thread_unlock_irqrestore(self, flags);
put_current_thread(self);
while (1) {
schedule(SCHED_NORMAL);