fix to walking thread list Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
wild-boar
Posts: 17
Joined: Thu May 08, 2014 11:58 pm
Been thanked: 9 times

fix to walking thread list

Post by wild-boar »

I recently upgraded a working project from 20.3.x to 21.6.x. I have custom code that uses chRegFirstThread() followed by chRegNextThread() to walk all threads. I noticed that chRegNextThread() always returns NULL for my application. This results in only seeing the first thread.

The following patch fixes chRegNextThread() when CH_CFG_USE_DYNAMIC == FALSE. It sets ntp to a value on the else statement.

Thanks!


Code: Select all

diff --git a/os/rt/src/chregistry.c b/os/rt/src/chregistry.c
index be0a40c6a..5318d9392 100644
--- a/os/rt/src/chregistry.c
+++ b/os/rt/src/chregistry.c
@@ -164,18 +164,18 @@ thread_t *chRegNextThread(thread_t *tp) {
   if (nqp == REG_HEADER(currcore)) {
     ntp = NULL;
   }
-#if CH_CFG_USE_DYNAMIC == TRUE
   else {
     uint8_t *p = (uint8_t *)nqp;
     /*lint -save -e413 [1.3] Safe to subtract a calculated offset.*/
     ntp = (thread_t *)(p - __CH_OFFSETOF(thread_t, rqueue));
     /*lint -restore*/
 
+#if CH_CFG_USE_DYNAMIC == TRUE
     chDbgAssert(ntp->refs < (trefs_t)255, "too many references");
 
     ntp->refs++;
-  }
 #endif
+  }
   chSysUnlock();
 #if CH_CFG_USE_DYNAMIC == TRUE
   chThdRelease(tp);
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: fix to walking thread list

Post by Giovanni »

Hi,

Fixed as bug #1170.

Giovanni
Post Reply