ChibiOS 21.11.4
Registry

Detailed Description

Threads Registry related APIs and services.

Operation mode

The Threads Registry is a double linked list that holds all the active threads in the system.
Operations defined for the registry:

  • First, returns the first, in creation order, active thread in the system.
  • Next, returns the next, in creation order, active thread in the system.

The registry is meant to be mainly a debug feature, for example, using 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.

Precondition
In order to use the threads registry the CH_CFG_USE_REGISTRY option must be enabled in chconf.h.
Collaboration diagram for Registry:

Data Structures

struct  chdebug_t
 ChibiOS/RT memory signature record. More...

Macros

#define REG_HEADER(oip)
 Access to the registry list header.
#define REG_REMOVE(tp)
 Removes a thread from the registry list.
#define REG_INSERT(oip, tp)
 Adds a thread to the registry list.

Functions

thread_tchRegFirstThread (void)
 Returns the first thread in the system.
thread_tchRegNextThread (thread_t *tp)
 Returns the thread next to the specified one.
thread_tchRegFindThreadByName (const char *name)
 Retrieves a thread pointer by name.
thread_tchRegFindThreadByPointer (thread_t *tp)
 Confirms that a pointer is a valid thread pointer.
thread_tchRegFindThreadByWorkingArea (stkalign_t *wa)
 Confirms that a working area is being used by some active thread.
static void __reg_object_init (registry_t *rp)
 Initializes a registry.
static void chRegSetThreadName (const char *name)
 Sets the current thread name.
static const char * chRegGetThreadNameX (thread_t *tp)
 Returns the name of the specified thread.
static void chRegSetThreadNameX (thread_t *tp, const char *name)
 Changes the name of the specified thread.

Variables

ROMCONST chdebug_t ch_debug
ROMCONST chdebug_t ch_debug

Macro Definition Documentation

◆ REG_HEADER

#define REG_HEADER ( oip)
Value:
ch_queue_t queue
Registry queue header.
Definition chobjects.h:132
Type of system data structure.
Definition chobjects.h:457
registry_t reglist
Registry header.
Definition chobjects.h:478

Access to the registry list header.

Definition at line 98 of file chregistry.h.

Referenced by chRegFirstThread(), chRegNextThread(), and chSysIntegrityCheckI().

◆ REG_REMOVE

#define REG_REMOVE ( tp)
Value:
(void) ch_queue_dequeue(&(tp)->rqueue)
static ch_queue_t * ch_queue_dequeue(ch_queue_t *p)
Removes an element from a queue and returns it.
Definition chlists.h:318

Removes a thread from the registry list.

Note
This macro is not meant for use in application code.
Parameters
[in]tpthread to remove from the registry

Definition at line 109 of file chregistry.h.

Referenced by chThdExitS(), and chThdRelease().

◆ REG_INSERT

#define REG_INSERT ( oip,
tp )
Value:
ch_queue_insert(REG_HEADER(oip), &(tp)->rqueue)
static void ch_queue_insert(ch_queue_t *qp, ch_queue_t *p)
Inserts an element into a queue.
Definition chlists.h:262
#define REG_HEADER(oip)
Access to the registry list header.
Definition chregistry.h:98

Adds a thread to the registry list.

Note
This macro is not meant for use in application code.
Parameters
[in]oippointer to the OS instance
[in]tpthread to add to the registry

Definition at line 118 of file chregistry.h.

Referenced by __thd_object_init().

Function Documentation

◆ chRegFirstThread()

thread_t * chRegFirstThread ( void )

Returns the first thread in the system.

Returns the most ancient thread in the system, usually this is the main thread unless it terminated. A reference is added to the returned thread in order to make sure its status is not lost.

Note
This function cannot return NULL because there is always at least one thread in the system.
Returns
A reference to the most ancient thread.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 159 of file chregistry.c.

References __CH_OFFSETOF, chSysLock, chSysUnlock, currcore, ch_thread::refs, REG_HEADER, and threadref.

Referenced by chRegFindThreadByName(), chRegFindThreadByPointer(), and chRegFindThreadByWorkingArea().

◆ chRegNextThread()

thread_t * chRegNextThread ( thread_t * tp)

Returns the thread next to the specified one.

The reference counter of the specified thread is decremented and the reference counter of the returned thread is incremented.

Parameters
[in]tppointer to the thread
Returns
A reference to the next thread.
Return values
NULLif there is no next thread.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 187 of file chregistry.c.

References __CH_OFFSETOF, chDbgAssert, chSysLock, chSysUnlock, chThdRelease(), currcore, ch_queue::next, ch_thread::refs, REG_HEADER, ch_thread::rqueue, and threadref.

Referenced by chRegFindThreadByName(), chRegFindThreadByPointer(), and chRegFindThreadByWorkingArea().

Here is the call graph for this function:

◆ chRegFindThreadByName()

thread_t * chRegFindThreadByName ( const char * name)

Retrieves a thread pointer by name.

Note
The reference counter of the found thread is increased by one so it cannot be disposed incidentally after the pointer has been returned.
Parameters
[in]namethe thread name
Returns
A pointer to the found thread.
Return values
NULLif a matching thread has not been found.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 230 of file chregistry.c.

References chRegFirstThread(), chRegGetThreadNameX(), and chRegNextThread().

Here is the call graph for this function:

◆ chRegFindThreadByPointer()

thread_t * chRegFindThreadByPointer ( thread_t * tp)

Confirms that a pointer is a valid thread pointer.

Note
The reference counter of the found thread is increased by one so it cannot be disposed incidentally after the pointer has been returned.
Parameters
[in]tppointer to the thread
Returns
A pointer to the found thread.
Return values
NULLif a matching thread has not been found.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 257 of file chregistry.c.

References chRegFirstThread(), and chRegNextThread().

Here is the call graph for this function:

◆ chRegFindThreadByWorkingArea()

thread_t * chRegFindThreadByWorkingArea ( stkalign_t * wa)

Confirms that a working area is being used by some active thread.

Note
The reference counter of the found thread is increased by one so it cannot be disposed incidentally after the pointer has been returned.
Parameters
[in]wapointer to a static working area
Returns
A pointer to the found thread.
Return values
NULLif a matching thread has not been found.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 286 of file chregistry.c.

References chRegFirstThread(), chRegNextThread(), and chThdGetWorkingAreaX().

Referenced by chThdCreate(), chThdCreateStatic(), and chThdCreateSuspended().

Here is the call graph for this function:

◆ __reg_object_init()

void __reg_object_init ( registry_t * rp)
inlinestatic

Initializes a registry.

Note
Internal use only.
Parameters
[out]rppointer to a registry_t structure
Function Class:
Object or module nitializer function.

Definition at line 151 of file chregistry.h.

References ch_queue_init(), and ch_registry::queue.

Referenced by chInstanceObjectInit(), and chSysInit().

Here is the call graph for this function:

◆ chRegSetThreadName()

void chRegSetThreadName ( const char * name)
inlinestatic

Sets the current thread name.

Precondition
This function only stores the pointer to the name if the option CH_CFG_USE_REGISTRY is enabled else no action is performed.
Parameters
[in]namethread name as a zero terminated string
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 165 of file chregistry.h.

References __sch_get_currthread.

◆ chRegGetThreadNameX()

const char * chRegGetThreadNameX ( thread_t * tp)
inlinestatic

Returns the name of the specified thread.

Precondition
This function only returns the pointer to the name if the option CH_CFG_USE_REGISTRY is enabled else NULL is returned.
Parameters
[in]tppointer to the thread
Returns
Thread name as a zero terminated string.
Return values
NULLif the thread name has not been set.

Definition at line 185 of file chregistry.h.

References ch_thread::name.

Referenced by chRegFindThreadByName().

◆ chRegSetThreadNameX()

void chRegSetThreadNameX ( thread_t * tp,
const char * name )
inlinestatic

Changes the name of the specified thread.

Precondition
This function only stores the pointer to the name if the option CH_CFG_USE_REGISTRY is enabled else no action is performed.
Parameters
[in]tppointer to the thread
[in]namethread name as a zero terminated string
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 205 of file chregistry.h.

References ch_thread::name.

Variable Documentation

◆ ch_debug [1/2]

ROMCONST chdebug_t ch_debug

Definition at line 77 of file chregistry.c.

Referenced by chInstanceObjectInit().

◆ ch_debug [2/2]

ROMCONST chdebug_t ch_debug
extern

Definition at line 77 of file chregistry.c.

Referenced by chInstanceObjectInit().