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

5
Last change on this file since f70079c was f70079c, checked in by Sebastian Huber <sebastian.huber@…>, on 11/25/18 at 19:26:02

score: Remove Objects_Information::the_api

Remove Objects_Information::the_class. This information is already
contained in Objects_Information::maximum_id.

Update #3621.

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