From dec37d5c12691746ecd7de2c9cf90f597b1193fd Mon Sep 17 00:00:00 2001 From: Joshua Phillips Date: Sat, 7 Feb 2009 12:15:50 +0000 Subject: [PATCH] Fixed thread_delete to delete current thread. --- kernel/exit.c | 3 +-- kernel/thread.c | 39 +++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 9b33f8e..0280dba 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -38,8 +38,7 @@ int sys_exit(struct syscall_args *args) TRACE("no current thread!"); return -1; } else { - TRACE("sys_exit called, but doing nothing"); - //thread_delete(thread); + thread_delete(thread); return 0; } } diff --git a/kernel/thread.c b/kernel/thread.c index 1c9dc50..18cbaea 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -30,6 +30,7 @@ #include "stdlib.h" #include "string.h" #include "trace.h" +#include "panic.h" #include "interrupt.h" #include "timer.h" @@ -195,22 +196,36 @@ void thread_suspend(struct thread *t) // need to switch away from it. } -void thread_delete(struct thread *t) +static void next_switch(void) { - // TODO: if this is the current thread, - // need to switch away from it - // TODO; more cleanup - if (t->prev){ - t->prev->next = t->next; - } else { - thread_first = t->next; - } - if (t->next){ - t->next->prev = t->prev; + struct thread *next_thread; + next_thread = get_next_thread(); + if (next_thread){ + switch_to_thread(next_thread); } else { - thread_last = t->prev; + panic("no threads"); } +} + +void thread_delete(struct thread *t) +{ + struct thread *thread_next; + + // remove from list + *(t->prev ? &t->prev->next : &thread_first) + = t->next; + *(t->next ? &t->next->prev : &thread_last) + = t->prev; + + // clean up the thread + // TODO; more cleanup free(t); + + // change from the thread, if it's current + if (t == thread_current){ + thread_current = thread_next; + next_switch(); + } } void yield_internal(void) -- 2.11.4.GIT