From 392c2fe70d224c4f564ebab5dcd3f0d607a546f0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 17 Mar 2010 13:04:42 +0000 Subject: Fixed bug 2971878 . git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1747 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chregistry.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'os/kernel') diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c index 4dca52534..5ed8ace2e 100644 --- a/os/kernel/src/chregistry.c +++ b/os/kernel/src/chregistry.c @@ -23,6 +23,16 @@ * * @addtogroup registry * @details Threads Registry related APIs and services.
+ * The threads Threads Registry is a double linked list that holds + * all the active threads in the system.
+ * The registry is meant to be mainly a debug feature, as example + * through the registry a debugger can enumerate the active threads + * in any given moment or the shell can print the active threads and + * their state.
+ * Another possible use is for centralized threads memory management, + * terminating threads can pulse an event source and an event handler + * can perform a scansion of the registry in order to recover the + * memory.
* In order to use the threads registry the @p CH_USE_REGISTRY option * must be enabled in @p chconf.h. * @{ @@ -64,25 +74,24 @@ Thread *chRegFirstThread(void) { * @retval NULL if there is no next thread. */ Thread *chRegNextThread(Thread *tp) { + Thread *ntp; chSysLock(); + ntp = tp->p_newer; + if (ntp == (Thread *)&rlist) + ntp = NULL; #if CH_USE_DYNAMIC - chDbgAssert(tp->p_refs > 0, "chRegNextThread(), #1", - "not referenced"); - tp->p_refs--; -#endif - if (tp->p_newer != (Thread *)&rlist) { - tp = tp->p_newer; -#if CH_USE_DYNAMIC - chDbgAssert(tp->p_refs < 255, "chRegNextThread(), #2", + else { + chDbgAssert(ntp->p_refs < 255, "chRegNextThread(), #1", "too many references"); - tp->p_refs++; -#endif + ntp->p_refs++; } - else - tp = NULL; +#endif chSysUnlock(); - return tp; +#if CH_USE_DYNAMIC + chThdRelease(tp); +#endif + return ntp; } #endif /* CH_USE_REGISTRY */ -- cgit v1.2.3