1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSScoreObject |
---|
5 | * |
---|
6 | * @brief Object Handler Data Structures |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2011. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_SCORE_OBJECTDATA_H |
---|
19 | #define _RTEMS_SCORE_OBJECTDATA_H |
---|
20 | |
---|
21 | #include <rtems/score/object.h> |
---|
22 | #include <rtems/score/chainimpl.h> |
---|
23 | #include <rtems/score/rbtree.h> |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | /** |
---|
30 | * @addtogroup RTEMSScoreObject |
---|
31 | * |
---|
32 | * @{ |
---|
33 | */ |
---|
34 | |
---|
35 | /** |
---|
36 | * The following defines the Object Control Block used to manage |
---|
37 | * each object local to this node. |
---|
38 | */ |
---|
39 | typedef struct { |
---|
40 | /** This is the chain node portion of an object. */ |
---|
41 | Chain_Node Node; |
---|
42 | /** This is the object's ID. */ |
---|
43 | Objects_Id id; |
---|
44 | /** This is the object's name. */ |
---|
45 | Objects_Name name; |
---|
46 | } Objects_Control; |
---|
47 | |
---|
48 | /** |
---|
49 | * This enumerated type is used in the class field of the object ID |
---|
50 | * for RTEMS internal object classes. |
---|
51 | */ |
---|
52 | typedef enum { |
---|
53 | OBJECTS_INTERNAL_NO_CLASS = 0, |
---|
54 | |
---|
55 | /* Must be one, see __Thread_Get_objects_information() */ |
---|
56 | OBJECTS_INTERNAL_THREADS = 1 |
---|
57 | } Objects_Internal_API; |
---|
58 | |
---|
59 | /** |
---|
60 | * This enumerated type is used in the class field of the object ID |
---|
61 | * for the RTEMS Classic API. |
---|
62 | */ |
---|
63 | typedef enum { |
---|
64 | OBJECTS_CLASSIC_NO_CLASS = 0, |
---|
65 | |
---|
66 | /* Must be one, see __Thread_Get_objects_information() */ |
---|
67 | OBJECTS_RTEMS_TASKS = 1, |
---|
68 | |
---|
69 | OBJECTS_RTEMS_TIMERS, |
---|
70 | OBJECTS_RTEMS_SEMAPHORES, |
---|
71 | OBJECTS_RTEMS_MESSAGE_QUEUES, |
---|
72 | OBJECTS_RTEMS_PARTITIONS, |
---|
73 | OBJECTS_RTEMS_REGIONS, |
---|
74 | OBJECTS_RTEMS_PORTS, |
---|
75 | OBJECTS_RTEMS_PERIODS, |
---|
76 | OBJECTS_RTEMS_EXTENSIONS, |
---|
77 | OBJECTS_RTEMS_BARRIERS |
---|
78 | } Objects_Classic_API; |
---|
79 | |
---|
80 | /** |
---|
81 | * This enumerated type is used in the class field of the object ID |
---|
82 | * for the POSIX API. |
---|
83 | */ |
---|
84 | typedef enum { |
---|
85 | OBJECTS_POSIX_NO_CLASS = 0, |
---|
86 | |
---|
87 | /* Must be one, see __Thread_Get_objects_information() */ |
---|
88 | OBJECTS_POSIX_THREADS = 1, |
---|
89 | |
---|
90 | OBJECTS_POSIX_KEYS, |
---|
91 | OBJECTS_POSIX_MESSAGE_QUEUES, |
---|
92 | OBJECTS_POSIX_SEMAPHORES, |
---|
93 | OBJECTS_POSIX_TIMERS, |
---|
94 | OBJECTS_POSIX_SHMS |
---|
95 | } Objects_POSIX_API; |
---|
96 | |
---|
97 | /** |
---|
98 | * @brief Constant for the object information string name length to indicate |
---|
99 | * that this object class has no string names. |
---|
100 | */ |
---|
101 | #define OBJECTS_NO_STRING_NAME 0 |
---|
102 | |
---|
103 | #if defined( RTEMS_MULTIPROCESSING ) |
---|
104 | struct _Thread_Control; |
---|
105 | |
---|
106 | /** |
---|
107 | * @brief This defines the Global Object Control Block used to manage objects |
---|
108 | * resident on other nodes. |
---|
109 | */ |
---|
110 | typedef struct { |
---|
111 | /** |
---|
112 | * @brief Nodes to manage active and inactive global objects. |
---|
113 | */ |
---|
114 | union { |
---|
115 | /** |
---|
116 | * @brief Inactive global objects reside on a chain. |
---|
117 | */ |
---|
118 | Chain_Node Inactive; |
---|
119 | |
---|
120 | struct { |
---|
121 | /** |
---|
122 | * @brief Node to lookup an active global object by identifier. |
---|
123 | */ |
---|
124 | RBTree_Node Id_lookup; |
---|
125 | |
---|
126 | /** |
---|
127 | * @brief Node to lookup an active global object by name. |
---|
128 | */ |
---|
129 | RBTree_Node Name_lookup; |
---|
130 | } Active; |
---|
131 | } Nodes; |
---|
132 | |
---|
133 | /** |
---|
134 | * @brief The global object identifier. |
---|
135 | */ |
---|
136 | Objects_Id id; |
---|
137 | |
---|
138 | /** |
---|
139 | * @brief The global object name. |
---|
140 | * |
---|
141 | * Using an unsigned thirty two bit value is broken but works. If any API is |
---|
142 | * MP with variable length names .. BOOM!!!! |
---|
143 | */ |
---|
144 | uint32_t name; |
---|
145 | } Objects_MP_Control; |
---|
146 | |
---|
147 | /** |
---|
148 | * @brief The MP object controls. |
---|
149 | * |
---|
150 | * Provided by the application via <rtems/confdefs.h>. |
---|
151 | */ |
---|
152 | extern Objects_MP_Control _Objects_MP_Controls[]; |
---|
153 | |
---|
154 | /** |
---|
155 | * The following type defines the callout used when a local task |
---|
156 | * is extracted from a remote thread queue (i.e. it's proxy must |
---|
157 | * extracted from the remote queue). |
---|
158 | */ |
---|
159 | typedef void ( *Objects_Thread_queue_Extract_callout )( |
---|
160 | struct _Thread_Control *, |
---|
161 | Objects_Id |
---|
162 | ); |
---|
163 | #endif |
---|
164 | |
---|
165 | /** |
---|
166 | * @brief The information structure used to manage each API class of objects. |
---|
167 | * |
---|
168 | * If objects for the API class are configured, an instance of this structure |
---|
169 | * is statically allocated and pre-initialized by OBJECTS_INFORMATION_DEFINE() |
---|
170 | * through <rtems/confdefs.h>. The RTEMS library contains a statically |
---|
171 | * allocated and pre-initialized instance for each API class providing zero |
---|
172 | * objects, see OBJECTS_INFORMATION_DEFINE_ZERO(). |
---|
173 | */ |
---|
174 | typedef struct { |
---|
175 | /** |
---|
176 | * @brief This is the maximum valid ID of this object API class. |
---|
177 | * |
---|
178 | * This member is statically initialized and provides also the object API, |
---|
179 | * class and multiprocessing node information. |
---|
180 | * |
---|
181 | * It is used by _Objects_Get() to validate an object ID. |
---|
182 | */ |
---|
183 | Objects_Id maximum_id; |
---|
184 | |
---|
185 | /** |
---|
186 | * @brief This points to the table of local object control blocks. |
---|
187 | * |
---|
188 | * This member is statically initialized. In case objects for this API class |
---|
189 | * are configured, it initially points to a statically allocated table |
---|
190 | * defined by <rtems/confdefs.h>. _Objects_Extend_information() may replace |
---|
191 | * the table with a larger one on demand. |
---|
192 | */ |
---|
193 | Objects_Control **local_table; |
---|
194 | |
---|
195 | /** |
---|
196 | * @brief This is the number of object control blocks on the inactive chain. |
---|
197 | * |
---|
198 | * This member is only used if unlimited objects are configured for this API |
---|
199 | * class. It is used to trigger calls to _Objects_Shrink_information() in |
---|
200 | * _Objects_Free(). |
---|
201 | */ |
---|
202 | Objects_Maximum inactive; |
---|
203 | |
---|
204 | /** |
---|
205 | * @brief This is the number of object control blocks in an allocation block. |
---|
206 | * |
---|
207 | * This member is statically initialized and read-only. It is only used if |
---|
208 | * unlimited objects are configured for this API class. It defines the count |
---|
209 | * of object control blocks used to extend and shrink this API class. |
---|
210 | */ |
---|
211 | Objects_Maximum objects_per_block; |
---|
212 | |
---|
213 | /** |
---|
214 | * @brief This is the size in bytes of each object control block. |
---|
215 | * |
---|
216 | * This member is statically initialized and read-only. |
---|
217 | */ |
---|
218 | uint16_t object_size; |
---|
219 | |
---|
220 | /** |
---|
221 | * @brief This is the maximum length of names. |
---|
222 | * |
---|
223 | * This member is statically initialized and read-only. A length of zero |
---|
224 | * indicates that this API class has a no string name |
---|
225 | * (OBJECTS_NO_STRING_NAME). |
---|
226 | */ |
---|
227 | uint16_t name_length; |
---|
228 | |
---|
229 | /** |
---|
230 | * @brief This is the chain of inactive object control blocks. |
---|
231 | * |
---|
232 | * This member is statically initialized to an empty chain. The |
---|
233 | * _Objects_Initialize_information() will populate this chain with the |
---|
234 | * object control blocks initially configured. |
---|
235 | */ |
---|
236 | Chain_Control Inactive; |
---|
237 | |
---|
238 | /** |
---|
239 | * @brief This is the number of inactive object control blocks per allocation |
---|
240 | * block. |
---|
241 | * |
---|
242 | * It is only used if unlimited objects are configured for this API class. |
---|
243 | */ |
---|
244 | Objects_Maximum *inactive_per_block; |
---|
245 | |
---|
246 | /** |
---|
247 | * @brief This is a table to allocation blocks of object control blocks. |
---|
248 | * |
---|
249 | * It is only used if unlimited objects are configured for this API class. |
---|
250 | * The object control blocks extend and shrink by these allocation blocks. |
---|
251 | */ |
---|
252 | Objects_Control **object_blocks; |
---|
253 | |
---|
254 | /** |
---|
255 | * @brief This points to the object control blocks initially available. |
---|
256 | * |
---|
257 | * This member is statically initialized and read-only. In case objects for |
---|
258 | * this API class are configured, it points to a statically allocated table |
---|
259 | * of object control blocks defined by <rtems/confdefs.h>, otherwise this |
---|
260 | * member is NULL. |
---|
261 | */ |
---|
262 | Objects_Control *initial_objects; |
---|
263 | |
---|
264 | #if defined(RTEMS_MULTIPROCESSING) |
---|
265 | /** |
---|
266 | * @brief This method is used by _Thread_queue_Extract_with_proxy(). |
---|
267 | * |
---|
268 | * This member is statically initialized and read-only. |
---|
269 | */ |
---|
270 | Objects_Thread_queue_Extract_callout extract; |
---|
271 | |
---|
272 | /** |
---|
273 | * @brief The global objects of this object information sorted by object ID. |
---|
274 | * |
---|
275 | * This member is statically initialized to an empty tree. The |
---|
276 | * _Objects_MP_Open() and _Objects_MP_Close() functions alter this tree. |
---|
277 | */ |
---|
278 | RBTree_Control Global_by_id; |
---|
279 | |
---|
280 | /** |
---|
281 | * @brief The global objects of this object information sorted by object |
---|
282 | * name. |
---|
283 | * |
---|
284 | * This member is statically initialized to an empty tree. The |
---|
285 | * _Objects_MP_Open() and _Objects_MP_Close() functions alter this tree. |
---|
286 | * |
---|
287 | * Objects with the same name are sorted according to their ID. |
---|
288 | */ |
---|
289 | RBTree_Control Global_by_name; |
---|
290 | #endif |
---|
291 | } Objects_Information; |
---|
292 | |
---|
293 | #if defined(RTEMS_MULTIPROCESSING) |
---|
294 | #define OBJECTS_INFORMATION_MP( name, extract ) \ |
---|
295 | , \ |
---|
296 | extract, \ |
---|
297 | RBTREE_INITIALIZER_EMPTY( name.Global_by_id ), \ |
---|
298 | RBTREE_INITIALIZER_EMPTY( name.Global_by_name ) |
---|
299 | #else |
---|
300 | #define OBJECTS_INFORMATION_MP( name, extract ) |
---|
301 | #endif |
---|
302 | |
---|
303 | /** |
---|
304 | * @brief Statically initializes an objects information. |
---|
305 | * |
---|
306 | * The initialized objects information contains no objects. |
---|
307 | * |
---|
308 | * @param name The object class C designator namespace prefix, e.g. _Semaphore. |
---|
309 | * @param api The object API number, e.g. OBJECTS_CLASSIC_API. |
---|
310 | * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES. |
---|
311 | * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for |
---|
312 | * objects without a string name. |
---|
313 | */ |
---|
314 | #define OBJECTS_INFORMATION_DEFINE_ZERO( name, api, cls, nl ) \ |
---|
315 | Objects_Information name##_Information = { \ |
---|
316 | _Objects_Build_id( api, cls, 1, 0 ), \ |
---|
317 | NULL, \ |
---|
318 | 0, \ |
---|
319 | 0, \ |
---|
320 | 0, \ |
---|
321 | nl, \ |
---|
322 | CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \ |
---|
323 | NULL, \ |
---|
324 | NULL, \ |
---|
325 | NULL \ |
---|
326 | OBJECTS_INFORMATION_MP( name##_Information, NULL ) \ |
---|
327 | } |
---|
328 | |
---|
329 | /** |
---|
330 | * @brief Statically initializes an objects information. |
---|
331 | * |
---|
332 | * The initialized objects information references a table with statically |
---|
333 | * allocated objects as specified by the object maximum parameter. These |
---|
334 | * objects must be registered via a call to _Objects_Information(). |
---|
335 | * |
---|
336 | * @param name The object class C designator namespace prefix, e.g. _Semaphore. |
---|
337 | * @param api The object API number, e.g. OBJECTS_CLASSIC_API. |
---|
338 | * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES. |
---|
339 | * @param type The object class type. |
---|
340 | * @param max The configured object maximum (the OBJECTS_UNLIMITED_OBJECTS flag |
---|
341 | * may be set). |
---|
342 | * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for |
---|
343 | * objects without a string name. |
---|
344 | * @param ex The optional object extraction method. Used only if |
---|
345 | * multiprocessing (RTEMS_MULTIPROCESSING) is enabled. |
---|
346 | */ |
---|
347 | #define OBJECTS_INFORMATION_DEFINE( name, api, cls, type, max, nl, ex ) \ |
---|
348 | static Objects_Control * \ |
---|
349 | name##_Local_table[ _Objects_Maximum_per_allocation( max ) ]; \ |
---|
350 | static type name##_Objects[ _Objects_Maximum_per_allocation( max ) ]; \ |
---|
351 | Objects_Information name##_Information = { \ |
---|
352 | _Objects_Build_id( api, cls, 1, _Objects_Maximum_per_allocation( max ) ), \ |
---|
353 | name##_Local_table, \ |
---|
354 | 0, \ |
---|
355 | _Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \ |
---|
356 | sizeof( type ), \ |
---|
357 | nl, \ |
---|
358 | CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \ |
---|
359 | NULL, \ |
---|
360 | NULL, \ |
---|
361 | &name##_Objects[ 0 ].Object \ |
---|
362 | OBJECTS_INFORMATION_MP( name##_Information, ex ) \ |
---|
363 | } |
---|
364 | |
---|
365 | /** @} */ |
---|
366 | |
---|
367 | #ifdef __cplusplus |
---|
368 | } |
---|
369 | #endif |
---|
370 | |
---|
371 | #endif |
---|
372 | /* end of include file */ |
---|