summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/score/objectdata.h
blob: 6139bfc1ecb9e17435d7a86730b38cbb6b333b6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/**
 * @file
 *
 * @ingroup ScoreObject
 *
 * @brief Object Handler Data Structures
 */

/*
 *  COPYRIGHT (c) 1989-2011.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifndef _RTEMS_SCORE_OBJECTDATA_H
#define _RTEMS_SCORE_OBJECTDATA_H

#include <rtems/score/object.h>
#include <rtems/score/chainimpl.h>
#include <rtems/score/rbtree.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @addtogroup ScoreObject
 *
 * @{
 */

/**
 *  The following defines the Object Control Block used to manage
 *  each object local to this node.
 */
typedef struct {
  /** This is the chain node portion of an object. */
  Chain_Node     Node;
  /** This is the object's ID. */
  Objects_Id     id;
  /** This is the object's name. */
  Objects_Name   name;
} Objects_Control;

/**
 *  This enumerated type is used in the class field of the object ID
 *  for RTEMS internal object classes.
 */
typedef enum {
  OBJECTS_INTERNAL_NO_CLASS =  0,
  OBJECTS_INTERNAL_THREADS  =  1
} Objects_Internal_API;

/**
 *  This enumerated type is used in the class field of the object ID
 *  for the RTEMS Classic API.
 */
typedef enum {
  OBJECTS_CLASSIC_NO_CLASS     = 0,
  OBJECTS_RTEMS_TASKS          = 1,
  OBJECTS_RTEMS_TIMERS         = 2,
  OBJECTS_RTEMS_SEMAPHORES     = 3,
  OBJECTS_RTEMS_MESSAGE_QUEUES = 4,
  OBJECTS_RTEMS_PARTITIONS     = 5,
  OBJECTS_RTEMS_REGIONS        = 6,
  OBJECTS_RTEMS_PORTS          = 7,
  OBJECTS_RTEMS_PERIODS        = 8,
  OBJECTS_RTEMS_EXTENSIONS     = 9,
  OBJECTS_RTEMS_BARRIERS       = 10
} Objects_Classic_API;

/**
 *  This enumerated type is used in the class field of the object ID
 *  for the POSIX API.
 */
typedef enum {
  OBJECTS_POSIX_NO_CLASS            = 0,
  OBJECTS_POSIX_THREADS             = 1,
  OBJECTS_POSIX_KEYS                = 2,
  OBJECTS_POSIX_INTERRUPTS          = 3,
  OBJECTS_POSIX_MESSAGE_QUEUES      = 5,
  OBJECTS_POSIX_SEMAPHORES          = 7,
  OBJECTS_POSIX_TIMERS              = 9,
  OBJECTS_POSIX_SHMS                = 12
} Objects_POSIX_API;

/**
 * @brief Constant for the object information string name length to indicate
 * that this object class has no string names.
 */
#define OBJECTS_NO_STRING_NAME 0

#if defined( RTEMS_MULTIPROCESSING )
struct _Thread_Control;

/**
 * @brief This defines the Global Object Control Block used to manage objects
 * resident on other nodes.
 */
typedef struct {
  /**
   * @brief Nodes to manage active and inactive global objects.
   */
  union {
    /**
     * @brief Inactive global objects reside on a chain.
     */
    Chain_Node Inactive;

    struct {
      /**
       * @brief Node to lookup an active global object by identifier.
       */
      RBTree_Node Id_lookup;

      /**
       * @brief Node to lookup an active global object by name.
       */
      RBTree_Node Name_lookup;
    } Active;
  } Nodes;

  /**
   * @brief The global object identifier.
   */
  Objects_Id id;

  /**
   * @brief The global object name.
   *
   * Using an unsigned thirty two bit value is broken but works.  If any API is
   * MP with variable length names .. BOOM!!!!
   */
  uint32_t name;
} Objects_MP_Control;

/**
 *  The following type defines the callout used when a local task
 *  is extracted from a remote thread queue (i.e. it's proxy must
 *  extracted from the remote queue).
 */
typedef void ( *Objects_Thread_queue_Extract_callout )(
  struct _Thread_Control *,
  Objects_Id
);
#endif

/**
 *  The following defines the structure for the information used to
 *  manage each class of objects.
 */
typedef struct {
  /** This is the maximum valid id of this object class. */
  Objects_Id        maximum_id;
  /** This points to the table of local objects. */
  Objects_Control **local_table;
  /** This is the number of objects on the Inactive list. */
  Objects_Maximum   inactive;
  /** This is the number of objects in a block. */
  Objects_Maximum   objects_per_block;
  /** This is the size in bytes of each object instance. */
  uint16_t          object_size;
  /**
   * @brief This is the maximum length of names.
   *
   * A length of zero indicates that this object has a no string name
   * (OBJECTS_NO_STRING_NAME).
   */
  uint16_t          name_length;
  /** This is the chain of inactive control blocks. */
  Chain_Control     Inactive;
  /** This is the number of inactive objects per block. */
  Objects_Maximum  *inactive_per_block;
  /** This is a table to the chain of inactive object memory blocks. */
  Objects_Control **object_blocks;
  Objects_Control  *initial_objects;
  #if defined(RTEMS_MULTIPROCESSING)
    /** This is this object class' method called when extracting a thread. */
    Objects_Thread_queue_Extract_callout extract;

    /**
     * @brief The global objects of this object information sorted by object
     * identifier.
     */
    RBTree_Control   Global_by_id;

    /**
     * @brief The global objects of this object information sorted by object
     * name.
     *
     * Objects with the same name are sorted according to their identifier.
     */
    RBTree_Control   Global_by_name;
  #endif
}   Objects_Information;

#if defined(RTEMS_MULTIPROCESSING)
#define OBJECTS_INFORMATION_MP( name, extract ) \
  , \
  extract, \
  RBTREE_INITIALIZER_EMPTY( name.Global_by_id ), \
  RBTREE_INITIALIZER_EMPTY( name.Global_by_name )
#else
#define OBJECTS_INFORMATION_MP( name, extract )
#endif

/**
 * @brief Statically initializes an objects information.
 *
 * The initialized objects information contains no objects.
 *
 * @param name The object class C designator namespace prefix, e.g. _Semaphore.
 * @param api The object API number, e.g. OBJECTS_CLASSIC_API.
 * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES.
 * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for
 *   objects without a string name.
 */
#define OBJECTS_INFORMATION_DEFINE_ZERO( name, api, cls, nl ) \
Objects_Information name##_Information = { \
  _Objects_Build_id( api, cls, 1, 0 ), \
  NULL, \
  0, \
  0, \
  0, \
  nl, \
  CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \
  NULL, \
  NULL, \
  NULL \
  OBJECTS_INFORMATION_MP( name##_Information, NULL ) \
}

/**
 * @brief Statically initializes an objects information.
 *
 * The initialized objects information references a table with statically
 * allocated objects as specified by the object maximum parameter.  These
 * objects must be registered via a call to _Objects_Information().
 *
 * @param name The object class C designator namespace prefix, e.g. _Semaphore.
 * @param api The object API number, e.g. OBJECTS_CLASSIC_API.
 * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES.
 * @param type The object class type.
 * @param max The configured object maximum (the OBJECTS_UNLIMITED_OBJECTS flag
 *   may be set).
 * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for
 *   objects without a string name.
 * @param ex The optional object extraction method.  Used only if
 *   multiprocessing (RTEMS_MULTIPROCESSING) is enabled.
 */
#define OBJECTS_INFORMATION_DEFINE( name, api, cls, type, max, nl, ex ) \
static Objects_Control * \
name##_Local_table[ _Objects_Maximum_per_allocation( max ) ]; \
static type name##_Objects[ _Objects_Maximum_per_allocation( max ) ]; \
Objects_Information name##_Information = { \
  _Objects_Build_id( api, cls, 1, _Objects_Maximum_per_allocation( max ) ), \
  name##_Local_table, \
  0, \
  _Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
  sizeof( type ), \
  nl, \
  CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \
  NULL, \
  NULL, \
  &name##_Objects[ 0 ].Object \
  OBJECTS_INFORMATION_MP( name##_Information, ex ) \
}

/** @} */

#ifdef __cplusplus
}
#endif

#endif
/* end of include file */