source: rtems/cpukit/score/inline/rtems/score/object.inl @ 4fc370e

4.115
Last change on this file since 4fc370e was 4fc370e, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 5, 2013 at 10:08:23 AM

score: Move thread dispatch content to new file

Move thread dispatch declarations and inline functions to new header
<rtems/score/threaddispatch.h> to make it independent of the
Thread_Control structure. This avoids a cyclic dependency in case
thread dispatch functions are used for the object implementation.

  • Property mode set to 100644
File size: 10.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief Inlined Routines in the Object Handler
5 *
6 * This include file contains the static inline implementation of all
7 * of the inlined routines in the Object Handler.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2011.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_OBJECT_H
20# error "Never use <rtems/score/object.inl> directly; include <rtems/score/object.h> instead."
21#endif
22
23#ifndef _RTEMS_SCORE_OBJECT_INL
24#define _RTEMS_SCORE_OBJECT_INL
25
26#include <rtems/score/threaddispatch.h>
27
28/**
29 * This function builds an object's id from the processor node and index
30 * values specified.
31 *
32 * @param[in] the_api indicates the API associated with this Id.
33 * @param[in] the_class indicates the class of object.
34 *            It is specific to @a the_api.
35 * @param[in] node is the node where this object resides.
36 * @param[in] index is the instance number of this object.
37 *
38 * @return This method returns an object Id constructed from the arguments.
39 */
40RTEMS_INLINE_ROUTINE Objects_Id _Objects_Build_id(
41  Objects_APIs     the_api,
42  uint32_t         the_class,
43  uint32_t         node,
44  uint32_t         index
45)
46{
47  return (( (Objects_Id) the_api )   << OBJECTS_API_START_BIT)   |
48         (( (Objects_Id) the_class ) << OBJECTS_CLASS_START_BIT) |
49         #if !defined(RTEMS_USE_16_BIT_OBJECT)
50           (( (Objects_Id) node )    << OBJECTS_NODE_START_BIT)  |
51         #endif
52         (( (Objects_Id) index )     << OBJECTS_INDEX_START_BIT);
53}
54
55/**
56 * This function returns the API portion of the ID.
57 *
58 * @param[in] id is the object Id to be processed.
59 *
60 * @return This method returns an object Id constructed from the arguments.
61 */
62RTEMS_INLINE_ROUTINE Objects_APIs _Objects_Get_API(
63  Objects_Id id
64)
65{
66  return (Objects_APIs) ((id >> OBJECTS_API_START_BIT) & OBJECTS_API_VALID_BITS);
67}
68
69/**
70 * This function returns the class portion of the ID.
71 *
72 * @param[in] id is the object Id to be processed
73 */
74RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_class(
75  Objects_Id id
76)
77{
78  return (uint32_t)
79    ((id >> OBJECTS_CLASS_START_BIT) & OBJECTS_CLASS_VALID_BITS);
80}
81
82/**
83 * This function returns the node portion of the ID.
84 *
85 * @param[in] id is the object Id to be processed
86 *
87 * @return This method returns the node portion of an object ID.
88 */
89RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_node(
90  Objects_Id id
91)
92{
93  /*
94   * If using 16-bit Ids, then there is no node field and it MUST
95   * be a single processor system.
96   */
97  #if defined(RTEMS_USE_16_BIT_OBJECT)
98    return 1;
99  #else
100    return (id >> OBJECTS_NODE_START_BIT) & OBJECTS_NODE_VALID_BITS;
101  #endif
102}
103
104/**
105 * This function returns the index portion of the ID.
106 *
107 * @param[in] id is the Id to be processed
108 *
109 * @return This method returns the class portion of the specified object ID.
110 */
111RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Get_index(
112  Objects_Id id
113)
114{
115  return
116    (Objects_Maximum)((id >> OBJECTS_INDEX_START_BIT) &
117                                          OBJECTS_INDEX_VALID_BITS);
118}
119
120/**
121 * This function returns true if the api is valid.
122 *
123 * @param[in] the_api is the api portion of an object ID.
124 *
125 * @return This method returns true if the specified api value is valid
126 *         and false otherwise.
127 */
128RTEMS_INLINE_ROUTINE bool _Objects_Is_api_valid(
129  uint32_t   the_api
130)
131{
132  if ( !the_api || the_api > OBJECTS_APIS_LAST )
133   return false;
134  return true;
135}
136
137/**
138 * This function returns true if the node is of the local object, and
139 * false otherwise.
140 *
141 * @param[in] node is the node number and corresponds to the node number
142 *        portion of an object ID.
143 *
144 * @return This method returns true if the specified node is the local node
145 *         and false otherwise.
146 */
147RTEMS_INLINE_ROUTINE bool _Objects_Is_local_node(
148  uint32_t   node
149)
150{
151  return ( node == _Objects_Local_node );
152}
153
154/**
155 * This function returns true if the id is of a local object, and
156 * false otherwise.
157 *
158 * @param[in] id is an object ID
159 *
160 * @return This method returns true if the specified object Id is local
161 *         and false otherwise.
162 *
163 * @note On a single processor configuration, this always returns true.
164 */
165RTEMS_INLINE_ROUTINE bool _Objects_Is_local_id(
166#if defined(RTEMS_MULTIPROCESSING)
167  Objects_Id id
168#else
169  Objects_Id id __attribute__((unused))
170#endif
171)
172{
173#if defined(RTEMS_MULTIPROCESSING)
174  return _Objects_Is_local_node( _Objects_Get_node(id) );
175#else
176  return true;
177#endif
178}
179
180/**
181 * This function returns true if left and right are equal,
182 * and false otherwise.
183 *
184 * @param[in] left is the Id on the left hand side of the comparison
185 * @param[in] right is the Id on the right hand side of the comparison
186 *
187 * @return This method returns true if the specified object IDs are equal
188 *         and false otherwise.
189 */
190RTEMS_INLINE_ROUTINE bool _Objects_Are_ids_equal(
191  Objects_Id left,
192  Objects_Id right
193)
194{
195  return ( left == right );
196}
197
198/**
199 * This function returns a pointer to the local_table object
200 * referenced by the index.
201 *
202 * @param[in] information points to an Object Information Table
203 * @param[in] index is the index of the object the caller wants to access
204 *
205 * @return This method returns a pointer to a local object or NULL if the
206 *         index is invalid and RTEMS_DEBUG is enabled.
207 */
208RTEMS_INLINE_ROUTINE Objects_Control *_Objects_Get_local_object(
209  Objects_Information *information,
210  uint16_t             index
211)
212{
213  /*
214   * This routine is ONLY to be called from places in the code
215   * where the Id is known to be good.  Therefore, this should NOT
216   * occur in normal situations.
217   */
218  #if defined(RTEMS_DEBUG)
219    if ( index > information->maximum )
220      return NULL;
221  #endif
222  return information->local_table[ index ];
223}
224
225/**
226 * This function sets the pointer to the local_table object
227 * referenced by the index.
228 *
229 * @param[in] information points to an Object Information Table
230 * @param[in] index is the index of the object the caller wants to access
231 * @param[in] the_object is the local object pointer
232 *
233 * @note This routine is ONLY to be called in places where the
234 *       index portion of the Id is known to be good.  This is
235 *       OK since it is normally called from object create/init
236 *       or delete/destroy operations.
237 */
238
239RTEMS_INLINE_ROUTINE void _Objects_Set_local_object(
240  Objects_Information *information,
241  uint32_t             index,
242  Objects_Control     *the_object
243)
244{
245  /*
246   *  This routine is ONLY to be called from places in the code
247   *  where the Id is known to be good.  Therefore, this should NOT
248   *  occur in normal situations.
249   */
250  #if defined(RTEMS_DEBUG)
251    if ( index > information->maximum )
252      return;
253  #endif
254
255  information->local_table[ index ] = the_object;
256}
257
258/**
259 * This function sets the pointer to the local_table object
260 * referenced by the index to a NULL so the object Id is invalid
261 * after this call.
262 *
263 * @param[in] information points to an Object Information Table
264 * @param[in] the_object is the local object pointer
265 *
266 * @note This routine is ONLY to be called in places where the
267 *       index portion of the Id is known to be good.  This is
268 *       OK since it is normally called from object create/init
269 *       or delete/destroy operations.
270 */
271
272RTEMS_INLINE_ROUTINE void _Objects_Invalidate_Id(
273  Objects_Information  *information,
274  Objects_Control      *the_object
275)
276{
277  _Objects_Set_local_object(
278    information,
279    _Objects_Get_index( the_object->id ),
280    NULL
281  );
282}
283
284/**
285 * This function places the_object control pointer and object name
286 * in the Local Pointer and Local Name Tables, respectively.
287 *
288 * @param[in] information points to an Object Information Table
289 * @param[in] the_object is a pointer to an object
290 * @param[in] name is the name of the object to make accessible
291 */
292RTEMS_INLINE_ROUTINE void _Objects_Open(
293  Objects_Information *information,
294  Objects_Control     *the_object,
295  Objects_Name         name
296)
297{
298  _Objects_Set_local_object(
299    information,
300    _Objects_Get_index( the_object->id ),
301    the_object
302  );
303
304  the_object->name = name;
305}
306
307/**
308 * This function places the_object control pointer and object name
309 * in the Local Pointer and Local Name Tables, respectively.
310 *
311 * @param[in] information points to an Object Information Table
312 * @param[in] the_object is a pointer to an object
313 * @param[in] name is the name of the object to make accessible
314 */
315RTEMS_INLINE_ROUTINE void _Objects_Open_u32(
316  Objects_Information *information,
317  Objects_Control     *the_object,
318  uint32_t             name
319)
320{
321  _Objects_Set_local_object(
322    information,
323    _Objects_Get_index( the_object->id ),
324    the_object
325  );
326
327  /* ASSERT: information->is_string == false */
328  the_object->name.name_u32 = name;
329}
330
331/**
332 * This function places the_object control pointer and object name
333 * in the Local Pointer and Local Name Tables, respectively.
334 *
335 * @param[in] information points to an Object Information Table
336 * @param[in] the_object is a pointer to an object
337 * @param[in] name is the name of the object to make accessible
338 */
339RTEMS_INLINE_ROUTINE void _Objects_Open_string(
340  Objects_Information *information,
341  Objects_Control     *the_object,
342  const char          *name
343)
344{
345  _Objects_Set_local_object(
346    information,
347    _Objects_Get_index( the_object->id ),
348    the_object
349  );
350
351  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
352    /* ASSERT: information->is_string */
353    the_object->name.name_p = name;
354  #endif
355}
356
357/**
358 * Returns if the object maximum specifies unlimited objects.
359 *
360 * @param[in] maximum The object maximum specification.
361 *
362 * @retval true Unlimited objects are available.
363 * @retval false The object count is fixed.
364 */
365RTEMS_INLINE_ROUTINE bool _Objects_Is_unlimited( uint32_t maximum )
366{
367  return (maximum & OBJECTS_UNLIMITED_OBJECTS) != 0;
368}
369
370/*
371 * We cannot use an inline function for this since it may be evaluated at
372 * compile time.
373 */
374#define _Objects_Maximum_per_allocation( maximum ) \
375  ((Objects_Maximum) ((maximum) & ~OBJECTS_UNLIMITED_OBJECTS))
376
377#endif
378/* end of include file */
Note: See TracBrowser for help on using the repository browser.