ChibiOS/RT  5.1.0
Registry
Collaboration diagram for 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:

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.

Macros

#define REG_REMOVE(tp)
 Removes a thread from the registry list. More...
 
#define REG_INSERT(tp)
 Adds a thread to the registry list. More...
 

Data Structures

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

Functions

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

Macro Definition Documentation

#define REG_REMOVE (   tp)
Value:
{ \
(tp)->older->newer = (tp)->newer; \
(tp)->newer->older = (tp)->older; \
}

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 83 of file chregistry.h.

Referenced by chThdExitS(), and chThdRelease().

#define REG_INSERT (   tp)
Value:
{ \
(tp)->newer = (thread_t *)&ch.rlist; \
(tp)->older = ch.rlist.older; \
(tp)->older->newer = (tp); \
ch.rlist.older = (tp); \
}
ready_list_t rlist
Ready list header.
Definition: chschd.h:415
ch_system_t ch
System data structures.
Definition: chschd.c:42
Structure representing a thread.
Definition: chschd.h:153

Adds a thread to the registry list.

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

Definition at line 94 of file chregistry.h.

Referenced by _thread_init().

Function Documentation

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 134 of file chregistry.c.

References ch, chSysLock(), chSysUnlock(), ch_thread::refs, and ch_system::rlist.

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

Here is the call graph for this function:

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 158 of file chregistry.c.

References ch, chDbgAssert, chSysLock(), chSysUnlock(), chThdRelease(), ch_thread::newer, ch_thread::refs, and ch_system::rlist.

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

Here is the call graph for this function:

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 194 of file chregistry.c.

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

Here is the call graph for this function:

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 221 of file chregistry.c.

References chRegFirstThread(), and chRegNextThread().

Here is the call graph for this function:

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 250 of file chregistry.c.

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

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

Here is the call graph for this function:

static 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 133 of file chregistry.h.

References ch, and ch_system::rlist.

static 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 153 of file chregistry.h.

References ch_thread::name.

Referenced by chRegFindThreadByName().

static 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 173 of file chregistry.h.

References ch_thread::name.