source: rtems/cpukit/score/include/rtems/score/objectimpl.h @ d7a12be9

5
Last change on this file since d7a12be9 was d7a12be9, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/16 at 12:14:10

score: Optimize _Objects_Get_no_protection()

Make the id the first parameter since usual callers get the object
identifier as the first parameter themself.

  • Property mode set to 100644
File size: 34.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.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_OBJECTIMPL_H
20#define _RTEMS_SCORE_OBJECTIMPL_H
21
22#include <rtems/score/object.h>
23#include <rtems/score/apimutex.h>
24#include <rtems/score/isrlock.h>
25#include <rtems/score/threaddispatch.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @addtogroup ScoreObject
33 *
34 * @{
35 */
36
37/**
38 *  Functions which compare names are prototyped like this.
39 */
40typedef bool    (*Objects_Name_comparators)(
41  void       * /* name_1 */,
42  void       * /* name_2 */,
43  uint16_t     /* length */
44);
45
46/**
47 *  This enumerated type is used in the class field of the object ID
48 *  for RTEMS internal object classes.
49 */
50typedef enum {
51  OBJECTS_INTERNAL_NO_CLASS =  0,
52  OBJECTS_INTERNAL_THREADS  =  1,
53  OBJECTS_INTERNAL_MUTEXES  =  2
54} Objects_Internal_API;
55
56/** This macro is used to generically specify the last API index. */
57#define OBJECTS_INTERNAL_CLASSES_LAST OBJECTS_INTERNAL_MUTEXES
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  OBJECTS_RTEMS_TASKS          = 1,
66  OBJECTS_RTEMS_TIMERS         = 2,
67  OBJECTS_RTEMS_SEMAPHORES     = 3,
68  OBJECTS_RTEMS_MESSAGE_QUEUES = 4,
69  OBJECTS_RTEMS_PARTITIONS     = 5,
70  OBJECTS_RTEMS_REGIONS        = 6,
71  OBJECTS_RTEMS_PORTS          = 7,
72  OBJECTS_RTEMS_PERIODS        = 8,
73  OBJECTS_RTEMS_EXTENSIONS     = 9,
74  OBJECTS_RTEMS_BARRIERS       = 10
75} Objects_Classic_API;
76
77/** This macro is used to generically specify the last API index. */
78#define OBJECTS_RTEMS_CLASSES_LAST OBJECTS_RTEMS_BARRIERS
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  OBJECTS_POSIX_THREADS             = 1,
87  OBJECTS_POSIX_KEYS                = 2,
88  OBJECTS_POSIX_INTERRUPTS          = 3,
89  OBJECTS_POSIX_MESSAGE_QUEUE_FDS   = 4,
90  OBJECTS_POSIX_MESSAGE_QUEUES      = 5,
91  OBJECTS_POSIX_MUTEXES             = 6,
92  OBJECTS_POSIX_SEMAPHORES          = 7,
93  OBJECTS_POSIX_CONDITION_VARIABLES = 8,
94  OBJECTS_POSIX_TIMERS              = 9,
95  OBJECTS_POSIX_BARRIERS            = 10,
96  OBJECTS_POSIX_SPINLOCKS           = 11,
97  OBJECTS_POSIX_RWLOCKS             = 12
98} Objects_POSIX_API;
99
100/** This macro is used to generically specify the last API index. */
101#define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_RWLOCKS
102
103/*
104 * For fake objects, which have an object identifier, but no objects
105 * information block.
106 */
107typedef enum {
108  OBJECTS_FAKE_OBJECTS_NO_CLASS   = 0,
109  OBJECTS_FAKE_OBJECTS_SCHEDULERS = 1
110} Objects_Fake_objects_API;
111
112/**
113 *  This enumerated type lists the locations which may be returned
114 *  by _Objects_Get.  These codes indicate the success of locating
115 *  an object with the specified ID.
116 */
117typedef enum {
118#if defined(RTEMS_MULTIPROCESSING)
119  OBJECTS_REMOTE = 2,         /* object is remote */
120#endif
121  OBJECTS_LOCAL  = 0,         /* object is local */
122  OBJECTS_ERROR  = 1          /* id was invalid */
123} Objects_Locations;
124
125#if defined(RTEMS_MULTIPROCESSING)
126/**
127 *  The following type defines the callout used when a local task
128 *  is extracted from a remote thread queue (i.e. it's proxy must
129 *  extracted from the remote queue).
130 */
131typedef void ( *Objects_Thread_queue_Extract_callout )(
132  Thread_Control *,
133  Objects_Id
134);
135#endif
136
137/**
138 *  The following defines the structure for the information used to
139 *  manage each class of objects.
140 */
141typedef struct {
142  /** This field indicates the API of this object class. */
143  Objects_APIs      the_api;
144  /** This is the class of this object set. */
145  uint16_t          the_class;
146  /** This is the minimum valid id of this object class. */
147  Objects_Id        minimum_id;
148  /** This is the maximum valid id of this object class. */
149  Objects_Id        maximum_id;
150  /** This is the maximum number of objects in this class. */
151  Objects_Maximum   maximum;
152  /** This is the true if unlimited objects in this class. */
153  bool              auto_extend;
154  /** This is the number of objects in a block. */
155  Objects_Maximum   allocation_size;
156  /** This is the size in bytes of each object instance. */
157  size_t            size;
158  /** This points to the table of local objects. */
159  Objects_Control **local_table;
160  /** This is the chain of inactive control blocks. */
161  Chain_Control     Inactive;
162  /** This is the number of objects on the Inactive list. */
163  Objects_Maximum   inactive;
164  /** This is the number of inactive objects per block. */
165  uint32_t         *inactive_per_block;
166  /** This is a table to the chain of inactive object memory blocks. */
167  void            **object_blocks;
168  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
169    /** This is true if names are strings. */
170    bool              is_string;
171  #endif
172  /** This is the maximum length of names. */
173  uint16_t          name_length;
174  #if defined(RTEMS_MULTIPROCESSING)
175    /** This is this object class' method called when extracting a thread. */
176    Objects_Thread_queue_Extract_callout extract;
177
178    /**
179     * @brief The global objects of this object information sorted by object
180     * identifier.
181     */
182    RBTree_Control   Global_by_id;
183
184    /**
185     * @brief The global objects of this object information sorted by object
186     * name.
187     *
188     * Objects with the same name are sorted according to their identifier.
189     */
190    RBTree_Control   Global_by_name;
191  #endif
192}   Objects_Information;
193
194/**
195 *  The following is referenced to the node number of the local node.
196 */
197#if defined(RTEMS_MULTIPROCESSING)
198extern uint16_t _Objects_Local_node;
199#else
200#define _Objects_Local_node ((uint16_t)1)
201#endif
202
203/**
204 *  The following is referenced to the number of nodes in the system.
205 */
206#if defined(RTEMS_MULTIPROCESSING)
207extern uint16_t _Objects_Maximum_nodes;
208#else
209#define _Objects_Maximum_nodes 1
210#endif
211
212/**
213 *  The following is the list of information blocks per API for each object
214 *  class.  From the ID, we can go to one of these information blocks,
215 *  and obtain a pointer to the appropriate object control block.
216 */
217extern Objects_Information
218    **_Objects_Information_table[OBJECTS_APIS_LAST + 1];
219
220/**
221 *  This function extends an object class information record.
222 *
223 *  @param[in] information points to an object class information block.
224 */
225void _Objects_Extend_information(
226  Objects_Information *information
227);
228
229/**
230 *  @brief Shrink an object class information record
231 *
232 *  This function shrink an object class information record.
233 *  The object's name and object space are released. The local_table
234 *  etc block does not shrink. The InActive list needs to be scanned
235 *  to find the objects are remove them.
236 *
237 *  @param[in] information points to an object class information block.
238 */
239void _Objects_Shrink_information(
240  Objects_Information *information
241);
242
243void _Objects_Do_initialize_information(
244  Objects_Information *information,
245  Objects_APIs         the_api,
246  uint16_t             the_class,
247  uint32_t             maximum,
248  uint16_t             size,
249  bool                 is_string,
250  uint32_t             maximum_name_length
251#if defined(RTEMS_MULTIPROCESSING)
252  ,
253  Objects_Thread_queue_Extract_callout extract
254#endif
255);
256
257/**
258 *  @brief Initialize object Information
259 *
260 *  This function initializes an object class information record.
261 *  SUPPORTS_GLOBAL is true if the object class supports global
262 *  objects, and false otherwise.  Maximum indicates the number
263 *  of objects required in this class and size indicates the size
264 *  in bytes of each control block for this object class.  The
265 *  name length and string designator are also set.  In addition,
266 *  the class may be a task, therefore this information is also included.
267 *
268 *  @param[in] information points to an object class information block.
269 *  @param[in] the_api indicates the API associated with this information block.
270 *  @param[in] the_class indicates the class of object being managed
271 *             by this information block.  It is specific to @a the_api.
272 *  @param[in] maximum is the maximum number of instances of this object
273 *             class which may be concurrently active.
274 *  @param[in] size is the size of the data structure for this class.
275 *  @param[in] is_string is true if this object uses string style names.
276 *  @param[in] maximum_name_length is the maximum length of object names.
277 */
278#if defined(RTEMS_MULTIPROCESSING)
279  #define _Objects_Initialize_information( \
280    information, \
281    the_api, \
282    the_class, \
283    maximum, \
284    size, \
285    is_string, \
286    maximum_name_length, \
287    extract \
288  ) \
289    _Objects_Do_initialize_information( \
290      information, \
291      the_api, \
292      the_class, \
293      maximum, \
294      size, \
295      is_string, \
296      maximum_name_length, \
297      extract \
298    )
299#else
300  #define _Objects_Initialize_information( \
301    information, \
302    the_api, \
303    the_class, \
304    maximum, \
305    size, \
306    is_string, \
307    maximum_name_length, \
308    extract \
309  ) \
310    _Objects_Do_initialize_information( \
311      information, \
312      the_api, \
313      the_class, \
314      maximum, \
315      size, \
316      is_string, \
317      maximum_name_length \
318    )
319#endif
320
321/**
322 *  @brief Object API Maximum Class
323 *
324 *  This function returns the highest numeric value of a valid
325 *  API for the specified @a api.
326 *
327 *  @param[in] api is the API of interest
328 *
329 *  @retval A positive integer on success and 0 otherwise.
330 */
331unsigned int _Objects_API_maximum_class(
332  uint32_t api
333);
334
335/**
336 * @brief Allocates an object without locking the allocator mutex.
337 *
338 * This function can be called in two contexts
339 * - the executing thread is the owner of the object allocator mutex, or
340 * - in case the system state is not up, e.g. during sequential system
341 *   initialization.
342 *
343 * @param[in] information The object information block.
344 *
345 * @retval NULL No object available.
346 * @retval object The allocated object.
347 *
348 * @see _Objects_Allocate() and _Objects_Free().
349 */
350Objects_Control *_Objects_Allocate_unprotected(
351  Objects_Information *information
352);
353
354/**
355 * @brief Allocates an object.
356 *
357 * This function locks the object allocator mutex via
358 * _Objects_Allocator_lock().  The caller must later unlock the object
359 * allocator mutex via _Objects_Allocator_unlock().  The caller must unlock the
360 * mutex in any case, even if the allocation failed due to resource shortage.
361 *
362 * A typical object allocation code looks like this:
363 * @code
364 * rtems_status_code some_create( rtems_id *id )
365 * {
366 *   rtems_status_code  sc;
367 *   Some_Control      *some;
368 *
369 *   // The object allocator mutex protects the executing thread from
370 *   // asynchronous thread restart and deletion.
371 *   some = (Some_Control *) _Objects_Allocate( &_Some_Information );
372 *
373 *   if ( some != NULL ) {
374 *     _Some_Initialize( some );
375 *     sc = RTEMS_SUCCESSFUL;
376 *   } else {
377 *     sc = RTEMS_TOO_MANY;
378 *   }
379 *
380 *   _Objects_Allocator_unlock();
381 *
382 *   return sc;
383 * }
384 * @endcode
385 *
386 * @param[in] information The object information block.
387 *
388 * @retval NULL No object available.
389 * @retval object The allocated object.
390 *
391 * @see _Objects_Free().
392 */
393Objects_Control *_Objects_Allocate( Objects_Information *information );
394
395/**
396 * @brief Frees an object.
397 *
398 * Appends the object to the chain of inactive objects.
399 *
400 * @param[in] information The object information block.
401 * @param[in] the_object The object to free.
402 *
403 * @see _Objects_Allocate().
404 *
405 * A typical object deletion code looks like this:
406 * @code
407 * rtems_status_code some_delete( rtems_id id )
408 * {
409 *   rtems_status_code  sc;
410 *   Some_Control      *some;
411 *   Objects_Locations  location;
412 *
413 *   // The object allocator mutex protects the executing thread from
414 *   // asynchronous thread restart and deletion.
415 *   _Objects_Allocator_lock();
416 *
417 *   // This will disable thread dispatching, so this starts a thread dispatch
418 *   // critical section.
419 *   some = (Semaphore_Control *)
420 *     _Objects_Get( &_Some_Information, id, &location );
421 *
422 *   switch ( location ) {
423 *     case OBJECTS_LOCAL:
424 *       // After the object close an object get with this identifier will
425 *       // fail.
426 *       _Objects_Close( &_Some_Information, &some->Object );
427 *
428 *       _Some_Delete( some );
429 *
430 *       // This enables thread dispatching, so the thread dispatch critical
431 *       // section ends here.
432 *       _Objects_Put( &some->Object );
433 *
434 *       // Thread dispatching is enabled.  The object free is only protected
435 *       // by the object allocator mutex.
436 *       _Objects_Free( &_Some_Information, &some->Object );
437 *
438 *       sc = RTEMS_SUCCESSFUL;
439 *       break;
440 *     default:
441 *       sc = RTEMS_INVALID_ID;
442 *       break;
443 *   }
444 *
445 *   _Objects_Allocator_unlock();
446 *
447 *   return sc;
448 * }
449 * @endcode
450 */
451void _Objects_Free(
452  Objects_Information *information,
453  Objects_Control     *the_object
454);
455
456/**
457 *  This function implements the common portion of the object
458 *  identification directives.  This directive returns the object
459 *  id associated with name.  If more than one object of this class
460 *  is named name, then the object to which the id belongs is
461 *  arbitrary.  Node indicates the extent of the search for the
462 *  id of the object named name.  If the object class supports global
463 *  objects, then the search can be limited to a particular node
464 *  or allowed to encompass all nodes.
465 */
466typedef enum {
467  OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL,
468  OBJECTS_INVALID_NAME,
469  OBJECTS_INVALID_ADDRESS,
470  OBJECTS_INVALID_ID,
471  OBJECTS_INVALID_NODE
472} Objects_Name_or_id_lookup_errors;
473
474/**
475 *  This macro defines the first entry in the
476 *  @ref Objects_Name_or_id_lookup_errors enumerated list.
477 */
478#define OBJECTS_NAME_ERRORS_FIRST OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL
479
480/**
481 *  This macro defines the last entry in the
482 *  @ref Objects_Name_or_id_lookup_errors enumerated list.
483 */
484#define OBJECTS_NAME_ERRORS_LAST  OBJECTS_INVALID_NODE
485
486/**
487 *  @brief Converts an object name to an Id.
488 *
489 *  This method converts an object name to an Id.  It performs a look up
490 *  using the object information block for this object class.
491 *
492 *  @param[in] information points to an object class information block.
493 *  @param[in] name is the name of the object to find.
494 *  @param[in] node is the set of nodes to search.
495 *  @param[in] id will contain the Id if the search is successful.
496 *
497 *  @retval This method returns one of the values from the
498 *          @ref Objects_Name_or_id_lookup_errors enumeration to indicate
499 *          successful or failure.  On success @a id will contain the Id of
500 *          the requested object.
501 */
502Objects_Name_or_id_lookup_errors _Objects_Name_to_id_u32(
503  Objects_Information *information,
504  uint32_t             name,
505  uint32_t             node,
506  Objects_Id          *id
507);
508
509typedef enum {
510  OBJECTS_GET_BY_NAME_INVALID_NAME,
511  OBJECTS_GET_BY_NAME_NAME_TOO_LONG,
512  OBJECTS_GET_BY_NAME_NO_OBJECT
513} Objects_Get_by_name_error;
514
515/**
516 * @brief Gets an object control block identified by its name.
517 *
518 * The object information must use string names.
519 *
520 * @param information The object information.  Must not be NULL.
521 * @param name The object name.
522 * @param name_length_p Optional parameter to return the name length.
523 * @param error The error indication in case of failure.  Must not be NULL.
524 *
525 * @retval NULL No object exists for this name or invalid parameters.
526 * @retval other The first object according to object index associated with
527 * this name.
528 */
529Objects_Control *_Objects_Get_by_name(
530  const Objects_Information *information,
531  const char                *name,
532  size_t                    *name_length_p,
533  Objects_Get_by_name_error *error
534);
535
536/**
537 *  @brief Implements the common portion of the object Id to name directives.
538 *
539 *  This function implements the common portion of the object Id
540 *  to name directives.  This function returns the name
541 *  associated with object id.
542 *
543 *  @param[in] id is the Id of the object whose name we are locating.
544 *  @param[in] name will contain the name of the object, if found.
545 *
546 *  @retval This method returns one of the values from the
547 *          @ref Objects_Name_or_id_lookup_errors enumeration to indicate
548 *          successful or failure.  On success @a name will contain the name of
549 *          the requested object.
550 *
551 *  @note This function currently does not support string names.
552 */
553Objects_Name_or_id_lookup_errors _Objects_Id_to_name (
554  Objects_Id      id,
555  Objects_Name   *name
556);
557
558/**
559 *  @brief Maps object ids to object control blocks.
560 *
561 *  This function maps object ids to object control blocks.
562 *  If id corresponds to a local object, then it returns
563 *  the_object control pointer which maps to id and location
564 *  is set to OBJECTS_LOCAL.  If the object class supports global
565 *  objects and the object id is global and resides on a remote
566 *  node, then location is set to OBJECTS_REMOTE, and the_object
567 *  is undefined.  Otherwise, location is set to OBJECTS_ERROR
568 *  and the_object is undefined.
569 *
570 *  @param[in] information points to an object class information block.
571 *  @param[in] id is the Id of the object whose name we are locating.
572 *  @param[in] location will contain an indication of success or failure.
573 *
574 *  @retval This method returns one of the values from the
575 *          @ref Objects_Name_or_id_lookup_errors enumeration to indicate
576 *          successful or failure.  On success @a id will contain the Id of
577 *          the requested object.
578 *
579 *  @note _Objects_Get returns with dispatching disabled for
580 *  local and remote objects.  _Objects_Get_isr_disable returns with
581 *  dispatching disabled for remote objects and interrupts for local
582 *  objects.
583 */
584Objects_Control *_Objects_Get (
585  Objects_Information *information,
586  Objects_Id           id,
587  Objects_Locations   *location
588);
589
590/**
591 *  @brief Maps object ids to object control blocks.
592 *
593 *  This function maps object ids to object control blocks.
594 *  If id corresponds to a local object, then it returns
595 *  the_object control pointer which maps to id and location
596 *  is set to OBJECTS_LOCAL.  If the object class supports global
597 *  objects and the object id is global and resides on a remote
598 *  node, then location is set to OBJECTS_REMOTE, and the_object
599 *  is undefined.  Otherwise, location is set to OBJECTS_ERROR
600 *  and the_object is undefined.
601 *
602 *  @param[in] information points to an object class information block.
603 *  @param[in] id is the Id of the object whose name we are locating.
604 *  @param[in] location will contain an indication of success or failure.
605 *  @param[in] lock_context is the previous interrupt state being turned.
606 *
607 *  @retval This method returns one of the values from the
608 *          @ref Objects_Name_or_id_lookup_errors enumeration to indicate
609 *          successful or failure.  On success @a name will contain the name of
610 *          the requested object.
611 *
612 *  @note _Objects_Get returns with dispatching disabled for
613 *  local and remote objects.  _Objects_Get_isr_disable returns with
614 *  dispatchng disabled for remote objects and interrupts for local
615 *  objects.
616 */
617Objects_Control *_Objects_Get_isr_disable(
618  Objects_Information *information,
619  Objects_Id           id,
620  Objects_Locations   *location,
621  ISR_lock_Context    *lock_context
622);
623
624/**
625 * @brief Maps the specified object identifier to the associated local object
626 * control block.
627 *
628 * In this function interrupts are disabled during the object lookup.  In case
629 * an associated object exists, then interrupts remain disabled, otherwise the
630 * previous interrupt state is restored.
631 *
632 * @param information The object class information block.
633 * @param[in] id The object identifier.
634 * @param[in] lock_context The interrupt lock context.
635 *
636 * @retval NULL No associated object exists.
637 * @retval other The pointer to the associated object control block.
638 * Interrupts are now disabled and must be restored using the specified lock
639 * context via _ISR_lock_ISR_enable() or _ISR_lock_Release_and_ISR_enable().
640 */
641Objects_Control *_Objects_Get_local(
642  const Objects_Information *information,
643  Objects_Id                 id,
644  ISR_lock_Context          *lock_context
645);
646
647/**
648 *  @brief  Maps object ids to object control blocks.
649 *
650 *  This function maps object ids to object control blocks.
651 *  If id corresponds to a local object, then it returns
652 *  the_object control pointer which maps to id and location
653 *  is set to OBJECTS_LOCAL.  If the object class supports global
654 *  objects and the object id is global and resides on a remote
655 *  node, then location is set to OBJECTS_REMOTE, and the_object
656 *  is undefined.  Otherwise, location is set to OBJECTS_ERROR
657 *  and the_object is undefined.
658 *
659 *  @param[in] id is the Id of the object whose name we are locating.
660 *    This is the first parameter since usual callers get the object identifier
661 *    as the first parameter themself.
662 *  @param[in] information points to an object class information block.
663 *
664 *  @retval This method returns one of the values from the
665 *          @ref Objects_Name_or_id_lookup_errors enumeration to indicate
666 *          successful or failure.  On success @a id will contain the Id of
667 *          the requested object.
668 *
669 *  @note _Objects_Get returns with dispatching disabled for
670 *  local and remote objects.  _Objects_Get_isr_disable returns with
671 *  dispatching disabled for remote objects and interrupts for local
672 *  objects.
673 */
674Objects_Control *_Objects_Get_no_protection(
675  Objects_Id                 id,
676  const Objects_Information *information
677);
678
679/**
680 *  Like @ref _Objects_Get, but is used to find "next" open
681 *  object.
682 *
683 *  Locks the object allocator mutex in case a next object exists.
684 *
685 *  @param[in] id is the Id of the object whose name we are locating.
686 *    This is the first parameter since usual callers get the object identifier
687 *    as the first parameter themself.
688 *  @param[in] information points to an object class information block.
689 *  @param[in] next_id_p is the Id of the next object we will look at.
690 *
691 *  @retval This method returns the pointer to the object located or
692 *          NULL on error.
693 */
694Objects_Control *_Objects_Get_next(
695  Objects_Id                 id,
696  const Objects_Information *information,
697  Objects_Id                *next_id_p
698);
699
700/**
701 *  @brief Get object information.
702 *
703 *  This function return the information structure given
704 *  an the API and Class.  This can be done independent of
705 *  the existence of any objects created by the API.
706 *
707 *  @param[in] the_api indicates the API for the information we want
708 *  @param[in] the_class indicates the Class for the information we want
709 *
710 *  @retval This method returns a pointer to the Object Information Table
711 *          for the class of objects which corresponds to this object ID.
712 */
713Objects_Information *_Objects_Get_information(
714  Objects_APIs   the_api,
715  uint16_t       the_class
716);
717
718/**
719 *  @brief Get information of an object from an ID.
720 *
721 *  This function return the information structure given
722 *  an @a id of an object.
723 *
724 *  @param[in] id is the object ID to get the information from
725 *
726 *  @retval This method returns a pointer to the Object Information Table
727 *          for the class of objects which corresponds to this object ID.
728 */
729Objects_Information *_Objects_Get_information_id(
730  Objects_Id  id
731);
732
733/**
734 *  @brief Gets object name in the form of a C string.
735 *
736 *  This method objects the name of an object and returns its name
737 *  in the form of a C string.  It attempts to be careful about
738 *  overflowing the user's string and about returning unprintable characters.
739 *
740 *  @param[in] id is the object to obtain the name of
741 *  @param[in] length indicates the length of the caller's buffer
742 *  @param[in] name points a string which will be filled in.
743 *
744 *  @retval This method returns @a name or NULL on error. @a *name will
745 *          contain the name if successful.
746 */
747char *_Objects_Get_name_as_string(
748  Objects_Id   id,
749  size_t       length,
750  char        *name
751);
752
753/**
754 *  @brief Set objects name.
755 *
756 *  This method sets the object name to either a copy of a string
757 *  or up to the first four characters of the string based upon
758 *  whether this object class uses strings for names.
759 *
760 *  @param[in] information points to the object information structure
761 *  @param[in] the_object is the object to operate upon
762 *  @param[in] name is a pointer to the name to use
763 *
764 *  @retval If successful, true is returned.  Otherwise false is returned.
765 */
766bool _Objects_Set_name(
767  Objects_Information *information,
768  Objects_Control     *the_object,
769  const char          *name
770);
771
772/**
773 *  @brief Removes object from namespace.
774 *
775 *  This function removes @a the_object from the namespace.
776 *
777 *  @param[in] information points to an Object Information Table.
778 *  @param[in] the_object is a pointer to an object.
779 */
780void _Objects_Namespace_remove(
781  Objects_Information  *information,
782  Objects_Control      *the_object
783);
784
785/**
786 *  @brief Close object.
787 *
788 *  This function removes the_object control pointer and object name
789 *  in the Local Pointer and Local Name Tables.
790 *
791 *  @param[in] information points to an Object Information Table
792 *  @param[in] the_object is a pointer to an object
793 */
794void _Objects_Close(
795  Objects_Information  *information,
796  Objects_Control      *the_object
797);
798
799/**
800 * @brief Returns the count of active objects.
801 *
802 * @param[in] information The object information table.
803 *
804 * @retval The count of active objects.
805 */
806Objects_Maximum _Objects_Active_count(
807  const Objects_Information *information
808);
809
810RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Extend_size(
811  const Objects_Information *information
812)
813{
814  return information->auto_extend ? information->allocation_size : 0;
815}
816
817/**
818 * This function returns true if the api is valid.
819 *
820 * @param[in] the_api is the api portion of an object ID.
821 *
822 * @return This method returns true if the specified api value is valid
823 *         and false otherwise.
824 */
825RTEMS_INLINE_ROUTINE bool _Objects_Is_api_valid(
826  uint32_t   the_api
827)
828{
829  if ( !the_api || the_api > OBJECTS_APIS_LAST )
830   return false;
831  return true;
832}
833
834/**
835 * This function returns true if the node is of the local object, and
836 * false otherwise.
837 *
838 * @param[in] node is the node number and corresponds to the node number
839 *        portion of an object ID.
840 *
841 * @return This method returns true if the specified node is the local node
842 *         and false otherwise.
843 */
844RTEMS_INLINE_ROUTINE bool _Objects_Is_local_node(
845  uint32_t   node
846)
847{
848  return ( node == _Objects_Local_node );
849}
850
851/**
852 * This function returns true if the id is of a local object, and
853 * false otherwise.
854 *
855 * @param[in] id is an object ID
856 *
857 * @return This method returns true if the specified object Id is local
858 *         and false otherwise.
859 *
860 * @note On a single processor configuration, this always returns true.
861 */
862RTEMS_INLINE_ROUTINE bool _Objects_Is_local_id(
863#if defined(RTEMS_MULTIPROCESSING)
864  Objects_Id id
865#else
866  Objects_Id id RTEMS_UNUSED
867#endif
868)
869{
870#if defined(RTEMS_MULTIPROCESSING)
871  return _Objects_Is_local_node( _Objects_Get_node(id) );
872#else
873  return true;
874#endif
875}
876
877/**
878 * This function returns true if left and right are equal,
879 * and false otherwise.
880 *
881 * @param[in] left is the Id on the left hand side of the comparison
882 * @param[in] right is the Id on the right hand side of the comparison
883 *
884 * @return This method returns true if the specified object IDs are equal
885 *         and false otherwise.
886 */
887RTEMS_INLINE_ROUTINE bool _Objects_Are_ids_equal(
888  Objects_Id left,
889  Objects_Id right
890)
891{
892  return ( left == right );
893}
894
895/**
896 * This function returns a pointer to the local_table object
897 * referenced by the index.
898 *
899 * @param[in] information points to an Object Information Table
900 * @param[in] index is the index of the object the caller wants to access
901 *
902 * @return This method returns a pointer to a local object or NULL if the
903 *         index is invalid and RTEMS_DEBUG is enabled.
904 */
905RTEMS_INLINE_ROUTINE Objects_Control *_Objects_Get_local_object(
906  Objects_Information *information,
907  uint16_t             index
908)
909{
910  /*
911   * This routine is ONLY to be called from places in the code
912   * where the Id is known to be good.  Therefore, this should NOT
913   * occur in normal situations.
914   */
915  #if defined(RTEMS_DEBUG)
916    if ( index > information->maximum )
917      return NULL;
918  #endif
919  return information->local_table[ index ];
920}
921
922/**
923 * This function sets the pointer to the local_table object
924 * referenced by the index.
925 *
926 * @param[in] information points to an Object Information Table
927 * @param[in] index is the index of the object the caller wants to access
928 * @param[in] the_object is the local object pointer
929 *
930 * @note This routine is ONLY to be called in places where the
931 *       index portion of the Id is known to be good.  This is
932 *       OK since it is normally called from object create/init
933 *       or delete/destroy operations.
934 */
935
936RTEMS_INLINE_ROUTINE void _Objects_Set_local_object(
937  Objects_Information *information,
938  uint32_t             index,
939  Objects_Control     *the_object
940)
941{
942  /*
943   *  This routine is ONLY to be called from places in the code
944   *  where the Id is known to be good.  Therefore, this should NOT
945   *  occur in normal situations.
946   */
947  #if defined(RTEMS_DEBUG)
948    if ( index > information->maximum )
949      return;
950  #endif
951
952  information->local_table[ index ] = the_object;
953}
954
955/**
956 * This function sets the pointer to the local_table object
957 * referenced by the index to a NULL so the object Id is invalid
958 * after this call.
959 *
960 * @param[in] information points to an Object Information Table
961 * @param[in] the_object is the local object pointer
962 *
963 * @note This routine is ONLY to be called in places where the
964 *       index portion of the Id is known to be good.  This is
965 *       OK since it is normally called from object create/init
966 *       or delete/destroy operations.
967 */
968
969RTEMS_INLINE_ROUTINE void _Objects_Invalidate_Id(
970  Objects_Information  *information,
971  Objects_Control      *the_object
972)
973{
974  _Assert( information != NULL );
975  _Assert( the_object != NULL );
976
977  _Objects_Set_local_object(
978    information,
979    _Objects_Get_index( the_object->id ),
980    NULL
981  );
982}
983
984/**
985 * This function places the_object control pointer and object name
986 * in the Local Pointer and Local Name Tables, respectively.
987 *
988 * @param[in] information points to an Object Information Table
989 * @param[in] the_object is a pointer to an object
990 * @param[in] name is the name of the object to make accessible
991 */
992RTEMS_INLINE_ROUTINE void _Objects_Open(
993  Objects_Information *information,
994  Objects_Control     *the_object,
995  Objects_Name         name
996)
997{
998  _Assert( information != NULL );
999  _Assert( the_object != NULL );
1000
1001  the_object->name = name;
1002
1003  _Objects_Set_local_object(
1004    information,
1005    _Objects_Get_index( the_object->id ),
1006    the_object
1007  );
1008}
1009
1010/**
1011 * This function places the_object control pointer and object name
1012 * in the Local Pointer and Local Name Tables, respectively.
1013 *
1014 * @param[in] information points to an Object Information Table
1015 * @param[in] the_object is a pointer to an object
1016 * @param[in] name is the name of the object to make accessible
1017 */
1018RTEMS_INLINE_ROUTINE void _Objects_Open_u32(
1019  Objects_Information *information,
1020  Objects_Control     *the_object,
1021  uint32_t             name
1022)
1023{
1024  /* ASSERT: information->is_string == false */
1025  the_object->name.name_u32 = name;
1026
1027  _Objects_Set_local_object(
1028    information,
1029    _Objects_Get_index( the_object->id ),
1030    the_object
1031  );
1032}
1033
1034/**
1035 * This function places the_object control pointer and object name
1036 * in the Local Pointer and Local Name Tables, respectively.
1037 *
1038 * @param[in] information points to an Object Information Table
1039 * @param[in] the_object is a pointer to an object
1040 * @param[in] name is the name of the object to make accessible
1041 */
1042RTEMS_INLINE_ROUTINE void _Objects_Open_string(
1043  Objects_Information *information,
1044  Objects_Control     *the_object,
1045  const char          *name
1046)
1047{
1048  #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
1049    /* ASSERT: information->is_string */
1050    the_object->name.name_p = name;
1051  #endif
1052
1053  _Objects_Set_local_object(
1054    information,
1055    _Objects_Get_index( the_object->id ),
1056    the_object
1057  );
1058}
1059
1060/**
1061 * @brief Puts back an object obtained with _Objects_Get().
1062 *
1063 * This function decrements the thread dispatch disable level.  The
1064 * _Thread_Dispatch() is called if the level reaches zero.
1065 */
1066RTEMS_INLINE_ROUTINE void _Objects_Put(
1067  Objects_Control *the_object
1068)
1069{
1070  (void) the_object;
1071  _Thread_Enable_dispatch();
1072}
1073
1074/**
1075 * @brief Puts back an object obtained with _Objects_Get().
1076 *
1077 * This function decrements the thread dispatch disable level.  The
1078 * _Thread_Dispatch() is not called if the level reaches zero, thus a thread
1079 * dispatch will not take place immediately on the current processor.
1080 */
1081RTEMS_INLINE_ROUTINE void _Objects_Put_without_thread_dispatch(
1082  Objects_Control *the_object
1083)
1084{
1085  (void) the_object;
1086  _Thread_Unnest_dispatch();
1087}
1088
1089/**
1090 * @brief Locks the object allocator mutex.
1091 *
1092 * While holding the allocator mutex the executing thread is protected from
1093 * asynchronous thread restart and deletion.
1094 *
1095 * The usage of the object allocator mutex with the thread life protection
1096 * makes it possible to allocate and free objects without thread dispatching
1097 * disabled.  The usage of a unified workspace and unlimited objects may lead
1098 * to heap fragmentation.  Thus the execution time of the _Objects_Allocate()
1099 * function may increase during system run-time.
1100 *
1101 * @see _Objects_Allocator_unlock() and _Objects_Allocate().
1102 */
1103RTEMS_INLINE_ROUTINE void _Objects_Allocator_lock( void )
1104{
1105  _RTEMS_Lock_allocator();
1106}
1107
1108/**
1109 * @brief Unlocks the object allocator mutex.
1110 *
1111 * In case the mutex is fully unlocked, then this function restores the
1112 * previous thread life protection state and thus may not return if the
1113 * executing thread was restarted or deleted in the mean-time.
1114 */
1115RTEMS_INLINE_ROUTINE void _Objects_Allocator_unlock( void )
1116{
1117  _RTEMS_Unlock_allocator();
1118}
1119
1120RTEMS_INLINE_ROUTINE bool _Objects_Allocator_is_owner( void )
1121{
1122  return _RTEMS_Allocator_is_owner();
1123}
1124
1125/** @} */
1126
1127#ifdef __cplusplus
1128}
1129#endif
1130
1131#if defined(RTEMS_MULTIPROCESSING)
1132#include <rtems/score/objectmp.h>
1133#endif
1134
1135
1136#endif
1137/* end of include file */
Note: See TracBrowser for help on using the repository browser.