#2423 closed enhancement (fixed)

rtems_iterate_over_all_threads lacks user callback private pointer pass through

Reported by: Jeffrey Hill Owned by:
Priority: normal Milestone: 5.1
Component: unspecified Version: 4.10
Severity: normal Keywords: rtems_iterate_over_all_threads callback private
Cc: Blocked By:
Blocking:

Description

Typically when designing an API that calls a user callback there is a user private "void *" pointer transparently passed through to the user callback so that the user can access his private state inside of his callback without being forced to employ a global variable. A global variable doesnt work very well if there are multiple objects instances created each of them using the same method with rtems_iterate_over_all_threads. This type of "void *" private pointer is of course a standard approach allowing the users callback to behave much the same way as a virtual method in C++, but nevertheless retaining a compatible C based API.

An enhanced version of the API might look like this.

void rtems_iterate_over_all_threads_xxx(
rtems_per_thread_routine routine, void * const pUserPrivatePassThrogh
);

typedef void (*rtems_per_thread_routine_xxx)(
Thread_Control *the_thread, void * const pUserPrivatePassThrogh
);

The pUserPrivatePassThrogh is not used by the library; it is retained for the duration of the rtems_iterate_over_all_threads_xxx function only so that it can be passed through to the user's callback.

thanks for your consideration of this matter

Change History (9)

comment:1 Changed on Sep 22, 2015 at 3:35:30 PM by Jeffrey Hill

PS: I am using rtems_iterate_over_all_threads to implement a task mode, thread aware, Ethernet connected GDB stub. When GDB attaches it stops certain threads and sends their status depending on its operating modes, but this of course should not apply to the GDB communication threads. Therefore there needs to be a way to iterate through all of the threads checking each of them to determine if they are tagged as being GDB stop-mode immune.

comment:2 Changed on Sep 22, 2015 at 8:02:27 PM by Jeffrey Hill

PPS: In thread.h and iterateoverthreads.c one could create some code like this. A possible implementation.

/ This defines the type for a method which operates on a single thread.

*/

typedef void (*rtems_per_thread_routine)( Thread_Control * );
typedef void (*rtems_per_task_function)( Thread_Control *,

void * const pUserPrivate );

/

  • This routine iterates over all threads regardless of API and
  • invokes the specified routine. */

void rtems_iterate_over_all_threads(

rtems_per_thread_routine routine

);

void rtems_thread_per_each_callback(rtems_per_task_function pFunction,

void * const pUserPrivate );

void rtems_thread_per_each_callback(rtems_per_task_function pFunction,

void * const pUserPrivate )

{

uint32_t i;
uint32_t api_index;
Thread_Control *the_thread;
Objects_Information *information;

if ( !pFunction )

return;

for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {

if ( !_Objects_Information_table[ api_index ] )

continue;

information = _Objects_Information_table[ api_index ][ 1 ];
if ( !information )

continue;

for ( i=1 ; i <= information->maximum ; i++ ) {

the_thread = (Thread_Control *)information->local_table[ i ];

if ( !the_thread )

continue;

(*pFunction)(the_thread,pUserPrivate);

}

}

}

comment:3 Changed on Sep 22, 2015 at 8:07:16 PM by Jeffrey Hill

Ok, yes, the names I choose are pretty lame.

comment:4 Changed on Oct 31, 2016 at 12:38:33 PM by Sebastian Huber

Milestone: 4.11.14.12

comment:5 Changed on Nov 2, 2016 at 8:13:53 AM by Sebastian Huber <sebastian.huber@…>

In d271c3bb78f86dd9417a964b019b8e38911064fa/rtems:

rtems: Add rtems_task_iterate()

Update #2423.

comment:6 Changed on Nov 2, 2016 at 8:14:03 AM by Sebastian Huber <sebastian.huber@…>

In 4cf58905b825ea8d2b9d677dc32d529390052d3a/rtems:

cpuuse: Use rtems_task_iterate()

Update #2423.

comment:7 Changed on Dec 14, 2016 at 2:25:44 PM by Sebastian Huber

Resolution: fixed
Status: newclosed

Documentation update done.

comment:8 Changed on May 11, 2017 at 7:31:02 AM by Sebastian Huber

Milestone: 4.124.12.0

comment:9 Changed on Nov 9, 2017 at 6:27:14 AM by Sebastian Huber

Milestone: 4.12.05.1

Milestone renamed

Note: See TracTickets for help on using tickets.