source: rtems/cpukit/include/rtems/score/objectimpl.h @ 3899bc1a

5
Last change on this file since 3899bc1a was 3899bc1a, checked in by Sebastian Huber <sebastian.huber@…>, on 11/24/18 at 10:51:28

score: Optimize object lookup

Use the maximum ID for the ID to object translation. Using the maximum
ID gets rid of an additional load from the object information in
_Objects_Get(). In addition, object lookups fail for every ID in case
the object information is cleared to zero. This makes it a bit more
robust during system startup (see new tests in spconfig02).

The local table no longer needs a NULL pointer entry at array index
zero. Adjust all the object iteration loops accordingly.

Remove Objects_Information::minimum_id since it contains only redundant
information. Add _Objects_Get_minimum_id() to get the minimum ID.

Update #3621.

  • Property mode set to 100644
File size: 30.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/objectdata.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_API;
54
55/** This macro is used to generically specify the last API index. */
56#define OBJECTS_INTERNAL_CLASSES_LAST OBJECTS_INTERNAL_THREADS
57
58/**
59 *  This enumerated type is used in the class field of the object ID
60 *  for the RTEMS Classic API.
61 */
62typedef enum {
63  OBJECTS_CLASSIC_NO_CLASS     = 0,
64  OBJECTS_RTEMS_TASKS          = 1,
65  OBJECTS_RTEMS_TIMERS         = 2,
66  OBJECTS_RTEMS_SEMAPHORES     = 3,
67  OBJECTS_RTEMS_MESSAGE_QUEUES = 4,
68  OBJECTS_RTEMS_PARTITIONS     = 5,
69  OBJECTS_RTEMS_REGIONS        = 6,
70  OBJECTS_RTEMS_PORTS          = 7,
71  OBJECTS_RTEMS_PERIODS        = 8,
72  OBJECTS_RTEMS_EXTENSIONS     = 9,
73  OBJECTS_RTEMS_BARRIERS       = 10
74} Objects_Classic_API;
75
76/** This macro is used to generically specify the last API index. */
77#define OBJECTS_RTEMS_CLASSES_LAST OBJECTS_RTEMS_BARRIERS
78
79/**
80 *  This enumerated type is used in the class field of the object ID
81 *  for the POSIX API.
82 */
83typedef enum {
84  OBJECTS_POSIX_NO_CLASS            = 0,
85  OBJECTS_POSIX_THREADS             = 1,
86  OBJECTS_POSIX_KEYS                = 2,
87  OBJECTS_POSIX_INTERRUPTS          = 3,
88  OBJECTS_POSIX_MESSAGE_QUEUES      = 5,
89  OBJECTS_POSIX_SEMAPHORES          = 7,
90  OBJECTS_POSIX_TIMERS              = 9,
91  OBJECTS_POSIX_SHMS                = 12
92} Objects_POSIX_API;
93
94/** This macro is used to generically specify the last API index. */
95#define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_SHMS
96
97/*
98 * For fake objects, which have an object identifier, but no objects
99 * information block.
100 */
101typedef enum {
102  OBJECTS_FAKE_OBJECTS_NO_CLASS   = 0,
103  OBJECTS_FAKE_OBJECTS_SCHEDULERS = 1
104} Objects_Fake_objects_API;
105
106#if defined(RTEMS_MULTIPROCESSING)
107/**
108 *  The following type defines the callout used when a local task
109 *  is extracted from a remote thread queue (i.e. it's proxy must
110 *  extracted from the remote queue).
111 */
112typedef void ( *Objects_Thread_queue_Extract_callout )(
113  Thread_Control *,
114  Objects_Id
115);
116#endif
117
118/**
119 *  The following defines the structure for the information used to
120 *  manage each class of objects.
121 */
122typedef struct {
123  /** This is the maximum valid id of this object class. */
124  Objects_Id        maximum_id;
125  /** This points to the table of local objects. */
126  Objects_Control **local_table;
127  /** This is the maximum number of objects in this class. */
128  Objects_Maximum   maximum;
129  /** This is the number of objects on the Inactive list. */
130  Objects_Maximum   inactive;
131  /** This is the number of objects in a block. */
132  Objects_Maximum   objects_per_block;
133  /** This is the size in bytes of each object instance. */
134  uint16_t          object_size;
135  /**
136   * @brief This is the maximum length of names.
137   *
138   * A length of zero indicates that this object has a no string name
139   * (OBJECTS_NO_STRING_NAME).
140   */
141  uint16_t          name_length;
142  /** This field indicates the API of this object class. */
143  uint8_t           the_api;
144  /** This is the class of this object set. */
145  uint8_t           the_class;
146  /** This is the true if unlimited objects in this class. */
147  bool              auto_extend;
148  /** This is the chain of inactive control blocks. */
149  Chain_Control     Inactive;
150  /** This is the number of inactive objects per block. */
151  Objects_Maximum  *inactive_per_block;
152  /** This is a table to the chain of inactive object memory blocks. */
153  Objects_Control **object_blocks;
154  #if defined(RTEMS_MULTIPROCESSING)
155    /** This is this object class' method called when extracting a thread. */
156    Objects_Thread_queue_Extract_callout extract;
157
158    /**
159     * @brief The global objects of this object information sorted by object
160     * identifier.
161     */
162    RBTree_Control   Global_by_id;
163
164    /**
165     * @brief The global objects of this object information sorted by object
166     * name.
167     *
168     * Objects with the same name are sorted according to their identifier.
169     */
170    RBTree_Control   Global_by_name;
171  #endif
172}   Objects_Information;
173
174/**
175 *  The following is referenced to the node number of the local node.
176 */
177#if defined(RTEMS_MULTIPROCESSING)
178extern uint16_t _Objects_Local_node;
179#else
180#define _Objects_Local_node ((uint16_t)1)
181#endif
182
183/**
184 *  The following is referenced to the number of nodes in the system.
185 */
186#if defined(RTEMS_MULTIPROCESSING)
187extern uint16_t _Objects_Maximum_nodes;
188#else
189#define _Objects_Maximum_nodes 1
190#endif
191
192/**
193 * This is the minimum object ID index associated with an object.
194 */
195#define OBJECTS_INDEX_MINIMUM 1U
196
197/**
198 *  The following is the list of information blocks per API for each object
199 *  class.  From the ID, we can go to one of these information blocks,
200 *  and obtain a pointer to the appropriate object control block.
201 */
202extern Objects_Information ** const
203_Objects_Information_table[ OBJECTS_APIS_LAST + 1 ];
204
205/**
206 *  This function extends an object class information record.
207 *
208 *  @param[in] information points to an object class information block.
209 */
210void _Objects_Extend_information(
211  Objects_Information *information
212);
213
214/**
215 *  @brief Shrink an object class information record
216 *
217 *  This function shrink an object class information record.
218 *  The object's name and object space are released. The local_table
219 *  etc block does not shrink. The InActive list needs to be scanned
220 *  to find the objects are remove them.
221 *
222 *  @param[in] information points to an object class information block.
223 */
224void _Objects_Shrink_information(
225  Objects_Information *information
226);
227
228void _Objects_Do_initialize_information(
229  Objects_Information *information,
230  Objects_APIs         the_api,
231  uint16_t             the_class,
232  uint32_t             maximum,
233  uint16_t             object_size,
234  uint16_t             maximum_name_length
235#if defined(RTEMS_MULTIPROCESSING)
236  ,
237  Objects_Thread_queue_Extract_callout extract
238#endif
239);
240
241/**
242 * @brief Constant for the object information string name length to indicate
243 * that this object class has no string names.
244 */
245#define OBJECTS_NO_STRING_NAME 0
246
247/**
248 *  @brief Initialize object Information
249 *
250 *  This function initializes an object class information record.
251 *  SUPPORTS_GLOBAL is true if the object class supports global
252 *  objects, and false otherwise.  Maximum indicates the number
253 *  of objects required in this class and size indicates the size
254 *  in bytes of each control block for this object class.  The
255 *  name length and string designator are also set.  In addition,
256 *  the class may be a task, therefore this information is also included.
257 *
258 *  @param[in] information points to an object class information block.
259 *  @param[in] the_api indicates the API associated with this information block.
260 *  @param[in] the_class indicates the class of object being managed
261 *             by this information block.  It is specific to @a the_api.
262 *  @param[in] maximum is the maximum number of instances of this object
263 *             class which may be concurrently active.
264 *  @param[in] object_size is the size of the data structure for this class.
265 *  @param[in] is_string is true if this object uses string style names.
266 *  @param[in] maximum_name_length is the maximum length of object names.
267 */
268#if defined(RTEMS_MULTIPROCESSING)
269  #define _Objects_Initialize_information( \
270    information, \
271    the_api, \
272    the_class, \
273    maximum, \
274    object_size, \
275    maximum_name_length, \
276    extract \
277  ) \
278    _Objects_Do_initialize_information( \
279      information, \
280      the_api, \
281      the_class, \
282      maximum, \
283      object_size, \
284      maximum_name_length, \
285      extract \
286    )
287#else
288  #define _Objects_Initialize_information( \
289    information, \
290    the_api, \
291    the_class, \
292    maximum, \
293    object_size, \
294    maximum_name_length, \
295    extract \
296  ) \
297    _Objects_Do_initialize_information( \
298      information, \
299      the_api, \
300      the_class, \
301      maximum, \
302      object_size, \
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  const Objects_Information *information,
694  Objects_Control           *the_object,
695  const char                *name
696);
697
698/**
699 * @brief Removes object with a 32-bit integer name from its namespace.
700 *
701 * @param[in] information The corresponding object information table.
702 * @param[in] the_object The object.
703 */
704void _Objects_Namespace_remove_u32(
705  const Objects_Information *information,
706  Objects_Control           *the_object
707);
708
709/**
710 * @brief Removes object with a string name from its namespace.
711 *
712 * @param[in] information The corresponding object information table.
713 * @param[in] the_object The object.
714 */
715void _Objects_Namespace_remove_string(
716  const Objects_Information *information,
717  Objects_Control           *the_object
718);
719
720/**
721 *  @brief Close object.
722 *
723 *  This function removes the_object control pointer and object name
724 *  in the Local Pointer and Local Name Tables.
725 *
726 *  @param[in] information points to an Object Information Table
727 *  @param[in] the_object is a pointer to an object
728 */
729void _Objects_Close(
730  const Objects_Information *information,
731  Objects_Control           *the_object
732);
733
734/**
735 * @brief Returns the count of active objects.
736 *
737 * @param[in] information The object information table.
738 *
739 * @retval The count of active objects.
740 */
741Objects_Maximum _Objects_Active_count(
742  const Objects_Information *information
743);
744
745RTEMS_INLINE_ROUTINE bool _Objects_Has_string_name(
746  const Objects_Information *information
747)
748{
749  return information->name_length > 0;
750}
751
752RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Extend_size(
753  const Objects_Information *information
754)
755{
756  return information->auto_extend ? information->objects_per_block : 0;
757}
758
759/**
760 * This function returns true if the api is valid.
761 *
762 * @param[in] the_api is the api portion of an object ID.
763 *
764 * @return This method returns true if the specified api value is valid
765 *         and false otherwise.
766 */
767RTEMS_INLINE_ROUTINE bool _Objects_Is_api_valid(
768  uint32_t   the_api
769)
770{
771  if ( !the_api || the_api > OBJECTS_APIS_LAST )
772   return false;
773  return true;
774}
775
776/**
777 * This function returns true if the node is of the local object, and
778 * false otherwise.
779 *
780 * @param[in] node is the node number and corresponds to the node number
781 *        portion of an object ID.
782 *
783 * @return This method returns true if the specified node is the local node
784 *         and false otherwise.
785 */
786RTEMS_INLINE_ROUTINE bool _Objects_Is_local_node(
787  uint32_t   node
788)
789{
790  return ( node == _Objects_Local_node );
791}
792
793/**
794 * This function returns true if the id is of a local object, and
795 * false otherwise.
796 *
797 * @param[in] id is an object ID
798 *
799 * @return This method returns true if the specified object Id is local
800 *         and false otherwise.
801 *
802 * @note On a single processor configuration, this always returns true.
803 */
804RTEMS_INLINE_ROUTINE bool _Objects_Is_local_id(
805#if defined(RTEMS_MULTIPROCESSING)
806  Objects_Id id
807#else
808  Objects_Id id RTEMS_UNUSED
809#endif
810)
811{
812#if defined(RTEMS_MULTIPROCESSING)
813  return _Objects_Is_local_node( _Objects_Get_node(id) );
814#else
815  return true;
816#endif
817}
818
819/**
820 * This function returns true if left and right are equal,
821 * and false otherwise.
822 *
823 * @param[in] left is the Id on the left hand side of the comparison
824 * @param[in] right is the Id on the right hand side of the comparison
825 *
826 * @return This method returns true if the specified object IDs are equal
827 *         and false otherwise.
828 */
829RTEMS_INLINE_ROUTINE bool _Objects_Are_ids_equal(
830  Objects_Id left,
831  Objects_Id right
832)
833{
834  return ( left == right );
835}
836
837/**
838 * Returns the identifier with the minimum index for the specified identifier.
839 *
840 * The specified identifier must have valid API, class and node fields.
841 *
842 * @param[in] id The identifier to be processed.
843 *
844 * @return The corresponding ID with the minimum index.
845 */
846RTEMS_INLINE_ROUTINE Objects_Id _Objects_Get_minimum_id( Objects_Id id )
847{
848  id &= ~OBJECTS_INDEX_MASK;
849  id += (Objects_Id) OBJECTS_INDEX_MINIMUM << OBJECTS_INDEX_START_BIT;
850  return id;
851}
852
853/**
854 * This function sets the pointer to the local_table object
855 * referenced by the index.
856 *
857 * @param[in] information points to an Object Information Table
858 * @param[in] index is the index of the object the caller wants to access
859 * @param[in] the_object is the local object pointer
860 *
861 * @note This routine is ONLY to be called in places where the
862 *       index portion of the Id is known to be good.  This is
863 *       OK since it is normally called from object create/init
864 *       or delete/destroy operations.
865 */
866
867RTEMS_INLINE_ROUTINE void _Objects_Set_local_object(
868  const Objects_Information *information,
869  uint32_t                   index,
870  Objects_Control           *the_object
871)
872{
873  /*
874   *  This routine is ONLY to be called from places in the code
875   *  where the Id is known to be good.  Therefore, this should NOT
876   *  occur in normal situations.
877   */
878  _Assert( index >= OBJECTS_INDEX_MINIMUM );
879  _Assert( index <= information->maximum );
880
881  information->local_table[ index - OBJECTS_INDEX_MINIMUM ] = the_object;
882}
883
884/**
885 * This function sets the pointer to the local_table object
886 * referenced by the index to a NULL so the object Id is invalid
887 * after this call.
888 *
889 * @param[in] information points to an Object Information Table
890 * @param[in] the_object is the local object pointer
891 *
892 * @note This routine is ONLY to be called in places where the
893 *       index portion of the Id is known to be good.  This is
894 *       OK since it is normally called from object create/init
895 *       or delete/destroy operations.
896 */
897
898RTEMS_INLINE_ROUTINE void _Objects_Invalidate_Id(
899  const Objects_Information *information,
900  Objects_Control           *the_object
901)
902{
903  _Assert( information != NULL );
904  _Assert( the_object != NULL );
905
906  _Objects_Set_local_object(
907    information,
908    _Objects_Get_index( the_object->id ),
909    NULL
910  );
911}
912
913/**
914 * This function places the_object control pointer and object name
915 * in the Local Pointer and Local Name Tables, respectively.
916 *
917 * @param[in] information points to an Object Information Table
918 * @param[in] the_object is a pointer to an object
919 * @param[in] name is the name of the object to make accessible
920 */
921RTEMS_INLINE_ROUTINE void _Objects_Open(
922  Objects_Information *information,
923  Objects_Control     *the_object,
924  Objects_Name         name
925)
926{
927  _Assert( information != NULL );
928  _Assert( the_object != NULL );
929
930  the_object->name = name;
931
932  _Objects_Set_local_object(
933    information,
934    _Objects_Get_index( the_object->id ),
935    the_object
936  );
937}
938
939/**
940 * This function places the_object control pointer and object name
941 * in the Local Pointer and Local Name Tables, respectively.
942 *
943 * @param[in] information points to an Object Information Table
944 * @param[in] the_object is a pointer to an object
945 * @param[in] name is the name of the object to make accessible
946 */
947RTEMS_INLINE_ROUTINE void _Objects_Open_u32(
948  const Objects_Information *information,
949  Objects_Control           *the_object,
950  uint32_t                   name
951)
952{
953  _Assert( !_Objects_Has_string_name( information ) );
954  the_object->name.name_u32 = name;
955
956  _Objects_Set_local_object(
957    information,
958    _Objects_Get_index( the_object->id ),
959    the_object
960  );
961}
962
963/**
964 * This function places the_object control pointer and object name
965 * in the Local Pointer and Local Name Tables, respectively.
966 *
967 * @param[in] information points to an Object Information Table
968 * @param[in] the_object is a pointer to an object
969 * @param[in] name is the name of the object to make accessible
970 */
971RTEMS_INLINE_ROUTINE void _Objects_Open_string(
972  const Objects_Information *information,
973  Objects_Control           *the_object,
974  const char                *name
975)
976{
977  _Assert( _Objects_Has_string_name( information ) );
978  the_object->name.name_p = name;
979
980  _Objects_Set_local_object(
981    information,
982    _Objects_Get_index( the_object->id ),
983    the_object
984  );
985}
986
987/**
988 * @brief Locks the object allocator mutex.
989 *
990 * While holding the allocator mutex the executing thread is protected from
991 * asynchronous thread restart and deletion.
992 *
993 * The usage of the object allocator mutex with the thread life protection
994 * makes it possible to allocate and free objects without thread dispatching
995 * disabled.  The usage of a unified workspace and unlimited objects may lead
996 * to heap fragmentation.  Thus the execution time of the _Objects_Allocate()
997 * function may increase during system run-time.
998 *
999 * @see _Objects_Allocator_unlock() and _Objects_Allocate().
1000 */
1001RTEMS_INLINE_ROUTINE void _Objects_Allocator_lock( void )
1002{
1003  _RTEMS_Lock_allocator();
1004}
1005
1006/**
1007 * @brief Unlocks the object allocator mutex.
1008 *
1009 * In case the mutex is fully unlocked, then this function restores the
1010 * previous thread life protection state and thus may not return if the
1011 * executing thread was restarted or deleted in the mean-time.
1012 */
1013RTEMS_INLINE_ROUTINE void _Objects_Allocator_unlock( void )
1014{
1015  _RTEMS_Unlock_allocator();
1016}
1017
1018RTEMS_INLINE_ROUTINE bool _Objects_Allocator_is_owner( void )
1019{
1020  return _RTEMS_Allocator_is_owner();
1021}
1022
1023/** @} */
1024
1025#ifdef __cplusplus
1026}
1027#endif
1028
1029#if defined(RTEMS_MULTIPROCESSING)
1030#include <rtems/score/objectmp.h>
1031#endif
1032
1033
1034#endif
1035/* end of include file */
Note: See TracBrowser for help on using the repository browser.