source: rtems/cpukit/include/rtems/score/objectdata.h @ 6135747

5
Last change on this file since 6135747 was 6135747, checked in by Sebastian Huber <sebastian.huber@…>, on 12/16/19 at 13:50:59

score: Split up objects free

Split up the different objects free methods into separate functions.
This helps to avoid a dependency on the workspace in case no objects or
a static set of objects is configured.

Update #3835.

  • Property mode set to 100644
File size: 12.6 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 * @brief The MP object controls.
149 *
150 * Provided by the application via <rtems/confdefs.h>.
151 */
152extern 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 */
159typedef void ( *Objects_Thread_queue_Extract_callout )(
160  struct _Thread_Control *,
161  Objects_Id
162);
163#endif
164
165typedef struct Objects_Information Objects_Information;
166
167/**
168 * @brief The information structure used to manage each API class of objects.
169 *
170 * If objects for the API class are configured, an instance of this structure
171 * is statically allocated and pre-initialized by OBJECTS_INFORMATION_DEFINE()
172 * through <rtems/confdefs.h>.  The RTEMS library contains a statically
173 * allocated and pre-initialized instance for each API class providing zero
174 * objects, see OBJECTS_INFORMATION_DEFINE_ZERO().
175 */
176struct Objects_Information {
177  /**
178   * @brief This is the maximum valid ID of this object API class.
179   *
180   * This member is statically initialized and provides also the object API,
181   * class and multiprocessing node information.
182   *
183   * It is used by _Objects_Get() to validate an object ID.
184   */
185  Objects_Id maximum_id;
186
187  /**
188   * @brief This points to the table of local object control blocks.
189   *
190   * This member is statically initialized.  In case objects for this API class
191   * are configured, it initially points to a statically allocated table
192   * defined by <rtems/confdefs.h>.  _Objects_Extend_information() may replace
193   * the table with a larger one on demand.
194   */
195  Objects_Control **local_table;
196
197  /**
198   * @brief Allocate an object.
199   *
200   * @see _Objects_Allocate_none(), _Objects_Allocate_static(), and
201   *   _Objects_Allocate_unlimited().
202   */
203  Objects_Control *( *allocate )( Objects_Information * );
204
205  /**
206   * @brief Free an object.
207   *
208   * In case _Objects_Allocate_none() is used, then this may be the NULL
209   * pointer.
210   *
211   * @see _Objects_Free_static(), and _Objects_Free_unlimited().
212   */
213  void ( *free )( Objects_Information *, Objects_Control * );
214
215  /**
216   * @brief This is the number of object control blocks on the inactive chain.
217   *
218   * This member is only used if unlimited objects are configured for this API
219   * class.  It is used to trigger calls to _Objects_Shrink_information() in
220   * _Objects_Free().
221   */
222  Objects_Maximum inactive;
223
224  /**
225   * @brief This is the number of object control blocks in an allocation block.
226   *
227   * This member is statically initialized and read-only.  It is only used if
228   * unlimited objects are configured for this API class.  It defines the count
229   * of object control blocks used to extend and shrink this API class.
230   */
231  Objects_Maximum objects_per_block;
232
233  /**
234   * @brief This is the size in bytes of each object control block.
235   *
236   * This member is statically initialized and read-only.
237   */
238  uint16_t object_size;
239
240  /**
241   * @brief This is the maximum length of names.
242   *
243   * This member is statically initialized and read-only.  A length of zero
244   * indicates that this API class has a no string name
245   * (OBJECTS_NO_STRING_NAME).
246   */
247  uint16_t name_length;
248
249  /**
250   * @brief This is the chain of inactive object control blocks.
251   *
252   * This member is statically initialized to an empty chain.  The
253   * _Objects_Initialize_information() will populate this chain with the
254   * object control blocks initially configured.
255   */
256  Chain_Control Inactive;
257
258  /**
259   * @brief This is the number of inactive object control blocks per allocation
260   * block.
261   *
262   * It is only used if unlimited objects are configured for this API class.
263   */
264  Objects_Maximum *inactive_per_block;
265
266  /**
267   * @brief This is a table to allocation blocks of object control blocks.
268   *
269   * It is only used if unlimited objects are configured for this API class.
270   * The object control blocks extend and shrink by these allocation blocks.
271   */
272  Objects_Control **object_blocks;
273
274  /**
275   * @brief This points to the object control blocks initially available.
276   *
277   * This member is statically initialized and read-only.  In case objects for
278   * this API class are configured, it points to a statically allocated table
279   * of object control blocks defined by <rtems/confdefs.h>, otherwise this
280   * member is NULL.
281   */
282  Objects_Control *initial_objects;
283
284#if defined(RTEMS_MULTIPROCESSING)
285  /**
286   * @brief This method is used by _Thread_queue_Extract_with_proxy().
287   *
288   * This member is statically initialized and read-only.
289   */
290  Objects_Thread_queue_Extract_callout extract;
291
292  /**
293   * @brief The global objects of this object information sorted by object ID.
294   *
295   * This member is statically initialized to an empty tree.  The
296   * _Objects_MP_Open() and _Objects_MP_Close() functions alter this tree.
297   */
298  RBTree_Control Global_by_id;
299
300  /**
301   * @brief The global objects of this object information sorted by object
302   * name.
303   *
304   * This member is statically initialized to an empty tree.  The
305   * _Objects_MP_Open() and _Objects_MP_Close() functions alter this tree.
306   *
307   * Objects with the same name are sorted according to their ID.
308   */
309  RBTree_Control Global_by_name;
310#endif
311};
312
313/**
314 * @brief Always return NULL.
315 *
316 * @param information The objects information.
317 *
318 * @retval NULL Always.
319 */
320Objects_Control *_Objects_Allocate_none( Objects_Information *information );
321
322/**
323 * @brief Return an inactive object or NULL.
324 *
325 * @param information The objects information.
326 *
327 * @retval NULL No inactive object is available.
328 * @retval object An inactive object.
329 */
330Objects_Control *_Objects_Allocate_static( Objects_Information *information );
331
332/**
333 * @brief Return an inactive object or NULL.
334 *
335 * Try to extend the objects information if necessary.
336 *
337 * @param information The objects information.
338 *
339 * @retval NULL No inactive object is available.
340 * @retval object An inactive object.
341 */
342Objects_Control *_Objects_Allocate_unlimited( Objects_Information *information );
343
344/**
345 * @brief Free the object.
346 *
347 * Append the object to the inactive chain of the objects information.
348 *
349 * @param information The objects information.
350 * @param the_object The object to free.
351 */
352void _Objects_Free_static(
353  Objects_Information *information,
354  Objects_Control     *the_object
355);
356
357/**
358 * @brief Free the object.
359 *
360 * Append the object to the inactive chain of the objects information and shrink
361 * the objects information if necessary.
362 *
363 * @param information The objects information.
364 * @param the_object The object to free.
365 */
366void _Objects_Free_unlimited(
367  Objects_Information *information,
368  Objects_Control     *the_object
369);
370
371#if defined(RTEMS_MULTIPROCESSING)
372#define OBJECTS_INFORMATION_MP( name, extract ) \
373  , \
374  extract, \
375  RBTREE_INITIALIZER_EMPTY( name.Global_by_id ), \
376  RBTREE_INITIALIZER_EMPTY( name.Global_by_name )
377#else
378#define OBJECTS_INFORMATION_MP( name, extract )
379#endif
380
381/**
382 * @brief Statically initializes an objects information.
383 *
384 * The initialized objects information contains no objects.
385 *
386 * @param name The object class C designator namespace prefix, e.g. _Semaphore.
387 * @param api The object API number, e.g. OBJECTS_CLASSIC_API.
388 * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES.
389 * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for
390 *   objects without a string name.
391 */
392#define OBJECTS_INFORMATION_DEFINE_ZERO( name, api, cls, nl ) \
393Objects_Information name##_Information = { \
394  _Objects_Build_id( api, cls, 1, 0 ), \
395  NULL, \
396  _Objects_Allocate_none, \
397  NULL, \
398  0, \
399  0, \
400  0, \
401  nl, \
402  CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \
403  NULL, \
404  NULL, \
405  NULL \
406  OBJECTS_INFORMATION_MP( name##_Information, NULL ) \
407}
408
409/**
410 * @brief Statically initializes an objects information.
411 *
412 * The initialized objects information references a table with statically
413 * allocated objects as specified by the object maximum parameter.  These
414 * objects must be registered via a call to _Objects_Information().
415 *
416 * @param name The object class C designator namespace prefix, e.g. _Semaphore.
417 * @param api The object API number, e.g. OBJECTS_CLASSIC_API.
418 * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES.
419 * @param type The object class type.
420 * @param max The configured object maximum (the OBJECTS_UNLIMITED_OBJECTS flag
421 *   may be set).
422 * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for
423 *   objects without a string name.
424 * @param ex The optional object extraction method.  Used only if
425 *   multiprocessing (RTEMS_MULTIPROCESSING) is enabled.
426 */
427#define OBJECTS_INFORMATION_DEFINE( name, api, cls, type, max, nl, ex ) \
428static Objects_Control * \
429name##_Local_table[ _Objects_Maximum_per_allocation( max ) ]; \
430static type name##_Objects[ _Objects_Maximum_per_allocation( max ) ]; \
431Objects_Information name##_Information = { \
432  _Objects_Build_id( api, cls, 1, _Objects_Maximum_per_allocation( max ) ), \
433  name##_Local_table, \
434  _Objects_Is_unlimited( max ) ? \
435    _Objects_Allocate_unlimited : _Objects_Allocate_static, \
436  _Objects_Is_unlimited( max ) ? \
437    _Objects_Free_unlimited : _Objects_Free_static, \
438  0, \
439  _Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
440  sizeof( type ), \
441  nl, \
442  CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \
443  NULL, \
444  NULL, \
445  &name##_Objects[ 0 ].Object \
446  OBJECTS_INFORMATION_MP( name##_Information, ex ) \
447}
448
449/** @} */
450
451#ifdef __cplusplus
452}
453#endif
454
455#endif
456/* end of include file */
Note: See TracBrowser for help on using the repository browser.