source: rtems/cpukit/include/rtems/score/objectdata.h @ 5803f37

5
Last change on this file since 5803f37 was 10251b3, checked in by Sebastian Huber <sebastian.huber@…>, on 05/22/19 at 05:51:14

score: Compact objects class indices

  • Property mode set to 100644
File size: 10.2 KB
Line 
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
26extern "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 */
39typedef 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 */
52typedef 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 */
63typedef 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 */
84typedef 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 )
104struct _Thread_Control;
105
106/**
107 * @brief This defines the Global Object Control Block used to manage objects
108 * resident on other nodes.
109 */
110typedef 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 *  The following type defines the callout used when a local task
149 *  is extracted from a remote thread queue (i.e. it's proxy must
150 *  extracted from the remote queue).
151 */
152typedef void ( *Objects_Thread_queue_Extract_callout )(
153  struct _Thread_Control *,
154  Objects_Id
155);
156#endif
157
158/**
159 * @brief The information structure used to manage each API class of objects.
160 *
161 * If objects for the API class are configured, an instance of this structure
162 * is statically allocated and pre-initialized by OBJECTS_INFORMATION_DEFINE()
163 * through <rtems/confdefs.h>.  The RTEMS library contains a statically
164 * allocated and pre-initialized instance for each API class providing zero
165 * objects, see OBJECTS_INFORMATION_DEFINE_ZERO().
166 */
167typedef struct {
168  /**
169   * @brief This is the maximum valid ID of this object API class.
170   *
171   * This member is statically initialized and provides also the object API,
172   * class and multiprocessing node information.
173   *
174   * It is used by _Objects_Get() to validate an object ID.
175   */
176  Objects_Id maximum_id;
177
178  /**
179   * @brief This points to the table of local object control blocks.
180   *
181   * This member is statically initialized.  In case objects for this API class
182   * are configured, it initially points to a statically allocated table
183   * defined by <rtems/confdefs.h>.  _Objects_Extend_information() may replace
184   * the table with a larger one on demand.
185   */
186  Objects_Control **local_table;
187
188  /**
189   * @brief This is the number of object control blocks on the inactive chain.
190   *
191   * This member is only used if unlimited objects are configured for this API
192   * class.  It is used to trigger calls to _Objects_Shrink_information() in
193   * _Objects_Free().
194   */
195  Objects_Maximum inactive;
196
197  /**
198   * @brief This is the number of object control blocks in an allocation block.
199   *
200   * This member is statically initialized and read-only.  It is only used if
201   * unlimited objects are configured for this API class.  It defines the count
202   * of object control blocks used to extend and shrink this API class.
203   */
204  Objects_Maximum objects_per_block;
205
206  /**
207   * @brief This is the size in bytes of each object control block.
208   *
209   * This member is statically initialized and read-only.
210   */
211  uint16_t object_size;
212
213  /**
214   * @brief This is the maximum length of names.
215   *
216   * This member is statically initialized and read-only.  A length of zero
217   * indicates that this API class has a no string name
218   * (OBJECTS_NO_STRING_NAME).
219   */
220  uint16_t name_length;
221
222  /**
223   * @brief This is the chain of inactive object control blocks.
224   *
225   * This member is statically initialized to an empty chain.  The
226   * _Objects_Initialize_information() will populate this chain with the
227   * object control blocks initially configured.
228   */
229  Chain_Control Inactive;
230
231  /**
232   * @brief This is the number of inactive object control blocks per allocation
233   * block.
234   *
235   * It is only used if unlimited objects are configured for this API class.
236   */
237  Objects_Maximum *inactive_per_block;
238
239  /**
240   * @brief This is a table to allocation blocks of object control blocks.
241   *
242   * It is only used if unlimited objects are configured for this API class.
243   * The object control blocks extend and shrink by these allocation blocks.
244   */
245  Objects_Control **object_blocks;
246
247  /**
248   * @brief This points to the object control blocks initially available.
249   *
250   * This member is statically initialized and read-only.  In case objects for
251   * this API class are configured, it points to a statically allocated table
252   * of object control blocks defined by <rtems/confdefs.h>, otherwise this
253   * member is NULL.
254   */
255  Objects_Control *initial_objects;
256
257#if defined(RTEMS_MULTIPROCESSING)
258  /**
259   * @brief This method is used by _Thread_queue_Extract_with_proxy().
260   *
261   * This member is statically initialized and read-only.
262   */
263  Objects_Thread_queue_Extract_callout extract;
264
265  /**
266   * @brief The global objects of this object information sorted by object ID.
267   *
268   * This member is statically initialized to an empty tree.  The
269   * _Objects_MP_Open() and _Objects_MP_Close() functions alter this tree.
270   */
271  RBTree_Control Global_by_id;
272
273  /**
274   * @brief The global objects of this object information sorted by object
275   * name.
276   *
277   * This member is statically initialized to an empty tree.  The
278   * _Objects_MP_Open() and _Objects_MP_Close() functions alter this tree.
279   *
280   * Objects with the same name are sorted according to their ID.
281   */
282  RBTree_Control Global_by_name;
283#endif
284} Objects_Information;
285
286#if defined(RTEMS_MULTIPROCESSING)
287#define OBJECTS_INFORMATION_MP( name, extract ) \
288  , \
289  extract, \
290  RBTREE_INITIALIZER_EMPTY( name.Global_by_id ), \
291  RBTREE_INITIALIZER_EMPTY( name.Global_by_name )
292#else
293#define OBJECTS_INFORMATION_MP( name, extract )
294#endif
295
296/**
297 * @brief Statically initializes an objects information.
298 *
299 * The initialized objects information contains no objects.
300 *
301 * @param name The object class C designator namespace prefix, e.g. _Semaphore.
302 * @param api The object API number, e.g. OBJECTS_CLASSIC_API.
303 * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES.
304 * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for
305 *   objects without a string name.
306 */
307#define OBJECTS_INFORMATION_DEFINE_ZERO( name, api, cls, nl ) \
308Objects_Information name##_Information = { \
309  _Objects_Build_id( api, cls, 1, 0 ), \
310  NULL, \
311  0, \
312  0, \
313  0, \
314  nl, \
315  CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \
316  NULL, \
317  NULL, \
318  NULL \
319  OBJECTS_INFORMATION_MP( name##_Information, NULL ) \
320}
321
322/**
323 * @brief Statically initializes an objects information.
324 *
325 * The initialized objects information references a table with statically
326 * allocated objects as specified by the object maximum parameter.  These
327 * objects must be registered via a call to _Objects_Information().
328 *
329 * @param name The object class C designator namespace prefix, e.g. _Semaphore.
330 * @param api The object API number, e.g. OBJECTS_CLASSIC_API.
331 * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES.
332 * @param type The object class type.
333 * @param max The configured object maximum (the OBJECTS_UNLIMITED_OBJECTS flag
334 *   may be set).
335 * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for
336 *   objects without a string name.
337 * @param ex The optional object extraction method.  Used only if
338 *   multiprocessing (RTEMS_MULTIPROCESSING) is enabled.
339 */
340#define OBJECTS_INFORMATION_DEFINE( name, api, cls, type, max, nl, ex ) \
341static Objects_Control * \
342name##_Local_table[ _Objects_Maximum_per_allocation( max ) ]; \
343static type name##_Objects[ _Objects_Maximum_per_allocation( max ) ]; \
344Objects_Information name##_Information = { \
345  _Objects_Build_id( api, cls, 1, _Objects_Maximum_per_allocation( max ) ), \
346  name##_Local_table, \
347  0, \
348  _Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
349  sizeof( type ), \
350  nl, \
351  CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \
352  NULL, \
353  NULL, \
354  &name##_Objects[ 0 ].Object \
355  OBJECTS_INFORMATION_MP( name##_Information, ex ) \
356}
357
358/** @} */
359
360#ifdef __cplusplus
361}
362#endif
363
364#endif
365/* end of include file */
Note: See TracBrowser for help on using the repository browser.