diff options
| author | bernard.xiong <[email protected]> | 2010-11-12 10:16:33 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2010-11-12 10:16:33 +0000 |
| commit | 7018ab0661e5a5c4be00283a5ab9eabc5d3ab0ee (patch) | |
| tree | d70c7e6b1b6cb495d680eaa876d1dedabc7e28d9 /src/thread.c | |
| parent | 5837cd792ccd5862bd9de0a2b0909b580116aa90 (diff) | |
add cleanup callback function on thread exit; add IPC object reset command.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1043 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'src/thread.c')
| -rw-r--r-- | src/thread.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/thread.c b/src/thread.c index 05eb403b56..32471bad3f 100644 --- a/src/thread.c +++ b/src/thread.c @@ -19,6 +19,7 @@ * 2006-09-03 Bernard implement rt_thread_detach * 2008-02-16 Bernard fix the rt_thread_timeout bug * 2010-03-21 Bernard change the errno of rt_thread_delay/sleep to RT_EOK. + * 2010-11-10 Bernard add cleanup callback function in thread exit. */ #include <rtthread.h> @@ -240,7 +241,8 @@ static void rt_thread_exit() /* enable interrupt */ rt_hw_interrupt_enable(temp); - if (rt_object_is_systemobject((rt_object_t)thread) == RT_EOK) + if ((rt_object_is_systemobject((rt_object_t)thread) == RT_EOK) && + thread->cleanup == RT_NULL) { rt_object_detach((rt_object_t)thread); } @@ -273,6 +275,8 @@ static void rt_thread_exit() */ rt_err_t rt_thread_detach (rt_thread_t thread) { + rt_base_t lock; + /* thread check */ RT_ASSERT(thread != RT_NULL); @@ -282,8 +286,24 @@ rt_err_t rt_thread_detach (rt_thread_t thread) /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); + /* change stat */ + thread->stat = RT_THREAD_CLOSE; + + /* detach object */ rt_object_detach((rt_object_t)thread); + if (thread->cleanup != RT_NULL) + { + /* disable interrupt */ + lock = rt_hw_interrupt_disable(); + + /* insert to defunct thread list */ + rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); + + /* enable interrupt */ + rt_hw_interrupt_enable(lock); + } + return RT_EOK; } |
