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

5
Last change on this file since de59c065 was de59c065, checked in by Sebastian Huber <sebastian.huber@…>, on 09/27/17 at 13:08:33

posix: Implement self-contained POSIX mutex

POSIX mutexes are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3112.

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