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

5
Last change on this file since ba776282 was ba776282, checked in by Gedare Bloom <gedare@…>, on 08/12/16 at 19:25:10

posix: shared memory support

Add POSIX shared memory manager (Shm). Includes a hook-based
approach for the backing memory storage that defaults to the
Workspace, and a test is provided using the heap. A test is
also provided for the basic use of mmap'ing a shared memory
object. This test currently fails at the mmap stage due to
no support for mmap.

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