ChibiOS/RT  5.1.0
chregistry.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 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; either version 3 of the License, or
9  (at your option) any later version.
10 
11  ChibiOS is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /**
21  * @file chregistry.h
22  * @brief Threads registry macros and structures.
23  *
24  * @addtogroup registry
25  * @{
26  */
27 
28 #ifndef CHREGISTRY_H
29 #define CHREGISTRY_H
30 
31 #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__)
32 
33 /*===========================================================================*/
34 /* Module constants. */
35 /*===========================================================================*/
36 
37 /*===========================================================================*/
38 /* Module pre-compile time settings. */
39 /*===========================================================================*/
40 
41 /*===========================================================================*/
42 /* Derived constants and error checks. */
43 /*===========================================================================*/
44 
45 /*===========================================================================*/
46 /* Module data structures and types. */
47 /*===========================================================================*/
48 
49 /**
50  * @brief ChibiOS/RT memory signature record.
51  */
52 typedef struct {
53  char identifier[4]; /**< @brief Always set to "main". */
54  uint8_t zero; /**< @brief Must be zero. */
55  uint8_t size; /**< @brief Size of this structure. */
56  uint16_t version; /**< @brief Encoded ChibiOS/RT version. */
57  uint8_t ptrsize; /**< @brief Size of a pointer. */
58  uint8_t timesize; /**< @brief Size of a @p systime_t. */
59  uint8_t threadsize; /**< @brief Size of a @p thread_t. */
60  uint8_t off_prio; /**< @brief Offset of @p prio field. */
61  uint8_t off_ctx; /**< @brief Offset of @p ctx field. */
62  uint8_t off_newer; /**< @brief Offset of @p newer field. */
63  uint8_t off_older; /**< @brief Offset of @p older field. */
64  uint8_t off_name; /**< @brief Offset of @p name field. */
65  uint8_t off_stklimit; /**< @brief Offset of @p stklimit field.*/
66  uint8_t off_state; /**< @brief Offset of @p state field. */
67  uint8_t off_flags; /**< @brief Offset of @p flags field. */
68  uint8_t off_refs; /**< @brief Offset of @p refs field. */
69  uint8_t off_preempt; /**< @brief Offset of @p preempt field. */
70  uint8_t off_time; /**< @brief Offset of @p time field. */
71 } chdebug_t;
72 
73 /*===========================================================================*/
74 /* Module macros. */
75 /*===========================================================================*/
76 
77 /**
78  * @brief Removes a thread from the registry list.
79  * @note This macro is not meant for use in application code.
80  *
81  * @param[in] tp thread to remove from the registry
82  */
83 #define REG_REMOVE(tp) { \
84  (tp)->older->newer = (tp)->newer; \
85  (tp)->newer->older = (tp)->older; \
86 }
87 
88 /**
89  * @brief Adds a thread to the registry list.
90  * @note This macro is not meant for use in application code.
91  *
92  * @param[in] tp thread to add to the registry
93  */
94 #define REG_INSERT(tp) { \
95  (tp)->newer = (thread_t *)&ch.rlist; \
96  (tp)->older = ch.rlist.older; \
97  (tp)->older->newer = (tp); \
98  ch.rlist.older = (tp); \
99 }
100 
101 /*===========================================================================*/
102 /* External declarations. */
103 /*===========================================================================*/
104 
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108  extern ROMCONST chdebug_t ch_debug;
109  thread_t *chRegFirstThread(void);
111  thread_t *chRegFindThreadByName(const char *name);
113  thread_t *chRegFindThreadByWorkingArea(stkalign_t *wa);
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* CH_CFG_USE_REGISTRY == TRUE */
119 
120 /*===========================================================================*/
121 /* Module inline functions. */
122 /*===========================================================================*/
123 
124 /**
125  * @brief Sets the current thread name.
126  * @pre This function only stores the pointer to the name if the option
127  * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
128  *
129  * @param[in] name thread name as a zero terminated string
130  *
131  * @api
132  */
133 static inline void chRegSetThreadName(const char *name) {
134 
135 #if CH_CFG_USE_REGISTRY == TRUE
136  ch.rlist.current->name = name;
137 #else
138  (void)name;
139 #endif
140 }
141 
142 /**
143  * @brief Returns the name of the specified thread.
144  * @pre This function only returns the pointer to the name if the option
145  * @p CH_CFG_USE_REGISTRY is enabled else @p NULL is returned.
146  *
147  * @param[in] tp pointer to the thread
148  *
149  * @return Thread name as a zero terminated string.
150  * @retval NULL if the thread name has not been set.
151  *
152  */
153 static inline const char *chRegGetThreadNameX(thread_t *tp) {
154 
155 #if CH_CFG_USE_REGISTRY == TRUE
156  return tp->name;
157 #else
158  (void)tp;
159  return NULL;
160 #endif
161 }
162 
163 /**
164  * @brief Changes the name of the specified thread.
165  * @pre This function only stores the pointer to the name if the option
166  * @p CH_CFG_USE_REGISTRY is enabled else no action is performed.
167  *
168  * @param[in] tp pointer to the thread
169  * @param[in] name thread name as a zero terminated string
170  *
171  * @xclass
172  */
173 static inline void chRegSetThreadNameX(thread_t *tp, const char *name) {
174 
175 #if CH_CFG_USE_REGISTRY == TRUE
176  tp->name = name;
177 #else
178  (void)tp;
179  (void)name;
180 #endif
181 }
182 
183 #endif /* CHREGISTRY_H */
184 
185 /** @} */
uint8_t off_name
Offset of name field.
Definition: chregistry.h:64
uint8_t off_prio
Offset of prio field.
Definition: chregistry.h:60
thread_t * chRegFindThreadByName(const char *name)
Retrieves a thread pointer by name.
Definition: chregistry.c:194
uint8_t off_flags
Offset of flags field.
Definition: chregistry.h:67
static const char * chRegGetThreadNameX(thread_t *tp)
Returns the name of the specified thread.
Definition: chregistry.h:153
thread_t * chRegFindThreadByPointer(thread_t *tp)
Confirms that a pointer is a valid thread pointer.
Definition: chregistry.c:221
uint16_t version
Encoded ChibiOS/RT version.
Definition: chregistry.h:56
uint8_t off_newer
Offset of newer field.
Definition: chregistry.h:62
uint8_t off_preempt
Offset of preempt field.
Definition: chregistry.h:69
uint8_t off_state
Offset of state field.
Definition: chregistry.h:66
thread_t * chRegFindThreadByWorkingArea(stkalign_t *wa)
Confirms that a working area is being used by some active thread.
Definition: chregistry.c:250
uint8_t zero
Must be zero.
Definition: chregistry.h:54
const char * name
Thread name or NULL.
Definition: chschd.h:166
ChibiOS/RT memory signature record.
Definition: chregistry.h:52
thread_t * chRegFirstThread(void)
Returns the first thread in the system.
Definition: chregistry.c:134
uint8_t off_older
Offset of older field.
Definition: chregistry.h:63
uint8_t ptrsize
Size of a pointer.
Definition: chregistry.h:57
ready_list_t rlist
Ready list header.
Definition: chschd.h:415
ch_system_t ch
System data structures.
Definition: chschd.c:42
uint8_t off_time
Offset of time field.
Definition: chregistry.h:70
static void chRegSetThreadNameX(thread_t *tp, const char *name)
Changes the name of the specified thread.
Definition: chregistry.h:173
uint8_t timesize
Size of a systime_t.
Definition: chregistry.h:58
uint8_t threadsize
Size of a thread_t.
Definition: chregistry.h:59
thread_t * chRegNextThread(thread_t *tp)
Returns the thread next to the specified one.
Definition: chregistry.c:158
uint8_t off_stklimit
Offset of stklimit field.
Definition: chregistry.h:65
uint8_t off_refs
Offset of refs field.
Definition: chregistry.h:68
uint8_t off_ctx
Offset of ctx field.
Definition: chregistry.h:61
static void chRegSetThreadName(const char *name)
Sets the current thread name.
Definition: chregistry.h:133
uint8_t size
Size of this structure.
Definition: chregistry.h:55
Structure representing a thread.
Definition: chschd.h:153