source: rtems/cpukit/score/include/rtems/score/objectimpl.h @ 36cd27c

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

score: Simplify _Objects_Get_next()

Remove unused location parameter.

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