ChibiOS/RT 7.0.6
chregistry.h
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006-2026 Giovanni Di Sirio.
3
4 This file is part of ChibiOS.
5
6 ChibiOS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation version 3 of the License.
9
10 ChibiOS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * @file rt/include/chregistry.h
21 * @brief Threads registry macros and structures.
22 *
23 * @addtogroup registry
24 * @{
25 */
26
27#ifndef CHREGISTRY_H
28#define CHREGISTRY_H
29
30#if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
31
32/*===========================================================================*/
33/* Module constants. */
34/*===========================================================================*/
35
36/*===========================================================================*/
37/* Module pre-compile time settings. */
38/*===========================================================================*/
39
40/*===========================================================================*/
41/* Derived constants and error checks. */
42/*===========================================================================*/
43
44/*===========================================================================*/
45/* Module data structures and types. */
46/*===========================================================================*/
47
48/**
49 * @brief ChibiOS/RT memory signature record.
50 */
51typedef struct {
52 char identifier[4]; /**< @brief Always set to "main". */
53 uint8_t zero; /**< @brief Must be zero. */
54 uint8_t size; /**< @brief Size of this structure. */
55 uint16_t version; /**< @brief Encoded ChibiOS/RT version. */
56 uint8_t ptrsize; /**< @brief Size of a pointer. */
57 uint8_t timesize; /**< @brief Size of a @p systime_t. */
58 uint8_t threadsize; /**< @brief Size of a @p thread_t. */
59 uint8_t off_prio; /**< @brief Offset of @p prio field. */
60 uint8_t off_ctx; /**< @brief Offset of @p ctx field. */
61 uint8_t off_newer; /**< @brief Offset of @p newer field. */
62 uint8_t off_older; /**< @brief Offset of @p older field. */
63 uint8_t off_name; /**< @brief Offset of @p name field. */
64 uint8_t off_stklimit; /**< @brief Offset of @p stklimit field.*/
65 uint8_t off_state; /**< @brief Offset of @p state field. */
66 uint8_t off_flags; /**< @brief Offset of @p flags field. */
67 uint8_t off_refs; /**< @brief Offset of @p refs field. */
68 uint8_t off_preempt; /**< @brief Offset of @p ticks field. */
69 uint8_t off_time; /**< @brief Offset of @p time field. */
70 uint8_t off_reserved[4];
71 uint8_t intctxsize; /**< @brief Size of a @p port_intctx. */
72 uint8_t intervalsize; /**< @brief Size of a @p sysinterval_t. */
73 uint8_t instancesnum; /**< @brief Number of instances. */
74 uint8_t off_sys_state; /**< @brief Offset of @p state field. */
75 uint8_t off_sys_instances; /**< @brief Offset of @p instances array
76 field. */
77 uint8_t off_sys_reglist; /**< @brief Offset of @p reglist field. */
78 uint8_t off_sys_rfcu; /**< @brief Offset of @p rfcu field. */
79 uint8_t off_sys_reserved[4];
80 uint8_t off_inst_rlist_current; /**< @brief Offset of @p rlist.current
81 field. */
82 uint8_t off_inst_rlist; /**< @brief Offset of @p rlist field. */
83 uint8_t off_inst_vtlist; /**< @brief Offset of @p vtlist field. */
84 uint8_t off_inst_reglist; /**< @brief Offset of @p reglist field. */
85 uint8_t off_inst_core_id; /**< @brief Offset of @p core_id field. */
86 uint8_t off_inst_rfcu; /**< @brief Offset of @p rfcu field. */
87} chdebug_t;
88
89/*===========================================================================*/
90/* Module macros. */
91/*===========================================================================*/
92
93/**
94 * @brief Access to the registry list header.
95 */
96#if (CH_CFG_SMP_MODE == TRUE) || defined(__DOXYGEN__)
97#define REG_HEADER(oip) (&ch_system.reglist.queue)
98#else
99#define REG_HEADER(oip) (&(oip)->reglist.queue)
100#endif
101
102/**
103 * @brief Removes a thread from the registry list.
104 * @note This macro is not meant for use in application code.
105 *
106 * @param[in] tp thread to remove from the registry
107 */
108#define REG_REMOVE(tp) (void) ch_queue_dequeue(&(tp)->rqueue)
109
110/**
111 * @brief Adds a thread to the registry list.
112 * @note This macro is not meant for use in application code.
113 *
114 * @param[in] oip pointer to the OS instance
115 * @param[in] tp thread to add to the registry
116 */
117#define REG_INSERT(oip, tp) ch_queue_insert(REG_HEADER(oip), &(tp)->rqueue)
118
119/*===========================================================================*/
120/* External declarations. */
121/*===========================================================================*/
122
123#ifdef __cplusplus
124extern "C" {
125#endif
126 extern ROMCONST chdebug_t ch_debug;
129 thread_t *chRegFindThreadByName(const char *name);
132#ifdef __cplusplus
133}
134#endif
135
136#endif /* CH_CFG_USE_REGISTRY == TRUE */
137
138/*===========================================================================*/
139/* Module inline functions. */
140/*===========================================================================*/
141
142/**
143 * @brief Initializes a registry.
144 * @note Internal use only.
145 *
146 * @param[out] rp pointer to a @p registry_t structure
147 *
148 * @init
149 */
150static inline void __reg_object_init(registry_t *rp) {
151
152 ch_queue_init(&rp->queue);
153}
154
155/**
156 * @brief Sets the current thread name.
157 * @pre This function only stores the pointer to the name if the option
158 * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
159 *
160 * @param[in] name thread name as a zero terminated string
161 *
162 * @api
163 */
164static inline void chRegSetThreadName(const char *name) {
165
166#if CH_CFG_USE_REGISTRY == TRUE
167 __sch_get_currthread()->name = name;
168#else
169 (void)name;
170#endif
171}
172
173/**
174 * @brief Returns the name of the specified thread.
175 * @pre This function only returns the pointer to the name if the option
176 * @p CH_CFG_USE_REGISTRY is enabled else @p NULL is returned.
177 *
178 * @param[in] tp pointer to the thread
179 *
180 * @return Thread name as a zero terminated string.
181 * @retval NULL if the thread name has not been set.
182 *
183 */
184static inline const char *chRegGetThreadNameX(thread_t *tp) {
185
186#if CH_CFG_USE_REGISTRY == TRUE
187 return tp->name;
188#else
189 (void)tp;
190 return NULL;
191#endif
192}
193
194/**
195 * @brief Changes the name of the specified thread.
196 * @pre This function only stores the pointer to the name if the option
197 * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
198 *
199 * @param[in] tp pointer to the thread
200 * @param[in] name thread name as a zero terminated string
201 *
202 * @xclass
203 */
204static inline void chRegSetThreadNameX(thread_t *tp, const char *name) {
205
206#if CH_CFG_USE_REGISTRY == TRUE
207 tp->name = name;
208#else
209 (void)tp;
210 (void)name;
211#endif
212}
213
214#endif /* CHREGISTRY_H */
215
216/** @} */
static void ch_queue_init(ch_queue_t *qp)
Queue initialization.
Definition chlists.h:221
struct ch_registry registry_t
Type of a registry structure.
port_stkalign_t stkalign_t
Definition chearly.h:79
struct ch_thread thread_t
Type of a thread structure.
Definition chearly.h:132
ROMCONST chdebug_t ch_debug
Definition chregistry.c:76
thread_t * chRegFirstThread(void)
Returns the first thread in the system.
Definition chregistry.c:158
thread_t * chRegNextThread(thread_t *tp)
Returns the thread next to the specified one.
Definition chregistry.c:186
thread_t * chRegFindThreadByName(const char *name)
Retrieves a thread pointer by name.
Definition chregistry.c:229
static const char * chRegGetThreadNameX(thread_t *tp)
Returns the name of the specified thread.
Definition chregistry.h:184
static void __reg_object_init(registry_t *rp)
Initializes a registry.
Definition chregistry.h:150
static void chRegSetThreadNameX(thread_t *tp, const char *name)
Changes the name of the specified thread.
Definition chregistry.h:204
static void chRegSetThreadName(const char *name)
Sets the current thread name.
Definition chregistry.h:164
thread_t * chRegFindThreadByWorkingArea(stkalign_t *wa)
Confirms that a working area is being used by some active thread.
Definition chregistry.c:285
thread_t * chRegFindThreadByPointer(thread_t *tp)
Confirms that a pointer is a valid thread pointer.
Definition chregistry.c:256
#define __sch_get_currthread()
Current thread pointer get macro.
Definition chschd.h:136
ch_queue_t queue
Registry queue header.
Definition chobjects.h:129
const char * name
Thread name or NULL.
Definition chobjects.h:189
ChibiOS/RT memory signature record.
Definition chregistry.h:51
uint8_t off_flags
Offset of flags field.
Definition chregistry.h:66
uint8_t off_inst_vtlist
Offset of vtlist field.
Definition chregistry.h:83
uint8_t off_sys_rfcu
Offset of rfcu field.
Definition chregistry.h:78
uint8_t off_inst_rlist_current
Offset of rlist.current field.
Definition chregistry.h:80
uint8_t off_sys_reglist
Offset of reglist field.
Definition chregistry.h:77
uint8_t off_inst_core_id
Offset of core_id field.
Definition chregistry.h:85
uint8_t off_newer
Offset of newer field.
Definition chregistry.h:61
uint8_t off_inst_rlist
Offset of rlist field.
Definition chregistry.h:82
uint8_t intctxsize
Size of a port_intctx.
Definition chregistry.h:71
uint8_t off_sys_state
Offset of state field.
Definition chregistry.h:74
uint8_t intervalsize
Size of a sysinterval_t.
Definition chregistry.h:72
uint8_t off_preempt
Offset of ticks field.
Definition chregistry.h:68
uint8_t off_older
Offset of older field.
Definition chregistry.h:62
uint8_t off_refs
Offset of refs field.
Definition chregistry.h:67
uint8_t off_time
Offset of time field.
Definition chregistry.h:69
char identifier[4]
Always set to "main".
Definition chregistry.h:52
uint8_t timesize
Size of a systime_t.
Definition chregistry.h:57
uint8_t instancesnum
Number of instances.
Definition chregistry.h:73
uint8_t off_stklimit
Offset of stklimit field.
Definition chregistry.h:64
uint8_t size
Size of this structure.
Definition chregistry.h:54
uint8_t off_sys_reserved[4]
Definition chregistry.h:79
uint8_t ptrsize
Size of a pointer.
Definition chregistry.h:56
uint8_t off_name
Offset of name field.
Definition chregistry.h:63
uint8_t off_state
Offset of state field.
Definition chregistry.h:65
uint8_t off_sys_instances
Offset of instances array field.
Definition chregistry.h:75
uint8_t off_inst_rfcu
Offset of rfcu field.
Definition chregistry.h:86
uint8_t zero
Must be zero.
Definition chregistry.h:53
uint16_t version
Encoded ChibiOS/RT version.
Definition chregistry.h:55
uint8_t threadsize
Size of a thread_t.
Definition chregistry.h:58
uint8_t off_reserved[4]
Definition chregistry.h:70
uint8_t off_inst_reglist
Offset of reglist field.
Definition chregistry.h:84
uint8_t off_prio
Offset of prio field.
Definition chregistry.h:59
uint8_t off_ctx
Offset of ctx field.
Definition chregistry.h:60