From a6eed37d26ba0ca617e8e1f3b3eca31449a26fdb Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 26 Feb 2016 10:28:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8950 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/src/chthreads.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'os/rt') diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index e809fbb13..943ca7d7c 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -462,9 +462,9 @@ void chThdExit(msg_t msg) { * @details The thread goes in the @p CH_STATE_FINAL state holding the * specified exit status code, other threads can retrieve the * exit status code by invoking the function @p chThdWait(). - * @post Exiting a thread that does not have references (detached) - * causes the thread to remain in the registry. It can only - * be removed by performing a registry scan operation. + * @post Exiting a non-static thread that does not have references + * (detached) causes the thread to remain in the registry. + * It can only be removed by performing a registry scan operation. * @post Eventual code after this function will never be executed, * this function never returns. The compiler has no way to * know this so do not assume that the compiler would remove @@ -490,6 +490,21 @@ void chThdExitS(msg_t msg) { } #endif +#if CH_CFG_USE_REGISTRY == TRUE + /* Static threads with no references are immediately removed from the + registry because there is no memory to recover.*/ +#if CH_CFG_USE_DYNAMIC == TRUE + if ((tp->refs == (trefs_t)0) && + (tp->flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) { + REG_REMOVE(tp); + } +#else + if (tp->refs == (trefs_t)0) { + REG_REMOVE(tp); + } +#endif +#endif + /* Going into final state.*/ chSchGoSleepS(CH_STATE_FINAL); -- cgit v1.2.3