fix to walking thread list Topic is solved

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

fix to walking thread list  Topic is solved

Postby wild-boar » Sun Aug 15, 2021 6:13 pm

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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: fix to walking thread list

Postby Giovanni » Mon Aug 16, 2021 7:22 am

Hi,

Fixed as bug #1170.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 13 guests