From 9a8e1fa4376d50da5db3bab01823293b6e15864c Mon Sep 17 00:00:00 2001 From: Bora Sahin Date: Tue, 17 Nov 2009 21:20:09 +0200 Subject: [PATCH] A few things needed in the destroy code paths of a thread are added. The first one is related to resource recycling. The parent which is waiting its child to exit did not delete its ktcb. Now, it deletes. The second one is related to self destroy. The added code wakes up all the waiters before it exits. --- src/api/thread.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/api/thread.c b/src/api/thread.c index 618a16d..1da38c3 100644 --- a/src/api/thread.c +++ b/src/api/thread.c @@ -105,12 +105,18 @@ int thread_destroy_children(void) void thread_destroy_self(unsigned int exit_code) { thread_destroy_children(); + + /* Wake up waiters */ + wake_up_all(¤t->wqh_send, WAKEUP_INTERRUPT); + wake_up_all(¤t->wqh_recv, WAKEUP_INTERRUPT); + current->exit_code = exit_code; sched_exit_sync(); } int thread_wait(struct ktcb *task) { + unsigned int exit_code; int ret; /* Wait until task switches to desired state */ @@ -118,8 +124,12 @@ int thread_wait(struct ktcb *task) task->state == TASK_DEAD, ret); if (ret < 0) return ret; - else - return (int)task->exit_code; + else { + exit_code = (int)task->exit_code; + tcb_remove(task); + tcb_delete(task); + return exit_code; + } } int thread_destroy(struct ktcb *task, unsigned int exit_code)