RTEMS
objectimpl.h
Go to the documentation of this file.
1 
12 /*
13  * COPYRIGHT (c) 1989-2011.
14  * On-Line Applications Research Corporation (OAR).
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifndef _RTEMS_SCORE_OBJECTIMPL_H
22 #define _RTEMS_SCORE_OBJECTIMPL_H
23 
24 #include <rtems/score/objectdata.h>
25 #include <rtems/score/apimutex.h>
26 #include <rtems/score/assert.h>
27 #include <rtems/score/isrlock.h>
28 #include <rtems/score/sysstate.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
44 typedef bool (*Objects_Name_comparators)(
45  void * /* name_1 */,
46  void * /* name_2 */,
47  uint16_t /* length */
48 );
49 
51 #define OBJECTS_INTERNAL_CLASSES_LAST OBJECTS_INTERNAL_THREADS
52 
54 #define OBJECTS_RTEMS_CLASSES_LAST OBJECTS_RTEMS_BARRIERS
55 
57 #define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_SHMS
58 
59 /*
60  * For fake objects, which have an object identifier, but no objects
61  * information block.
62  */
63 typedef enum {
64  OBJECTS_FAKE_OBJECTS_NO_CLASS = 0,
65  OBJECTS_FAKE_OBJECTS_SCHEDULERS = 1
66 } Objects_Fake_objects_API;
67 
71 #if defined(RTEMS_MULTIPROCESSING)
72 extern uint16_t _Objects_Maximum_nodes;
73 #else
74 #define _Objects_Maximum_nodes 1
75 #endif
76 
80 #define OBJECTS_INDEX_MINIMUM 1U
81 
87 extern Objects_Information ** const
89 
99  Objects_Information *information
100 );
101 
109  Objects_Information *information,
110  Objects_Maximum block
111 );
112 
124  Objects_Information *information
125 );
126 
136 
148 unsigned int _Objects_API_maximum_class(
149  uint32_t api
150 );
151 
192 
203 typedef enum {
204  OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL,
205  OBJECTS_INVALID_NAME,
206  OBJECTS_INVALID_ADDRESS,
207  OBJECTS_INVALID_ID,
208  OBJECTS_INVALID_NODE
210 
215 #define OBJECTS_NAME_ERRORS_FIRST OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL
216 
221 #define OBJECTS_NAME_ERRORS_LAST OBJECTS_INVALID_NODE
222 
243  uint32_t name,
244  uint32_t node,
245  Objects_Id *id,
246  const Objects_Information *information
247 );
248 
249 typedef enum {
250  OBJECTS_GET_BY_NAME_INVALID_NAME,
251  OBJECTS_GET_BY_NAME_NAME_TOO_LONG,
252  OBJECTS_GET_BY_NAME_NO_OBJECT
253 } Objects_Get_by_name_error;
254 
270  const Objects_Information *information,
271  const char *name,
272  size_t *name_length_p,
273  Objects_Get_by_name_error *error
274 );
275 
293  Objects_Id id,
294  Objects_Name *name
295 );
296 
318  Objects_Id id,
319  ISR_lock_Context *lock_context,
320  const Objects_Information *information
321 );
322 
344  Objects_Id id,
345  const Objects_Information *information
346 );
347 
363  Objects_Id id,
364  const Objects_Information *information,
365  Objects_Id *next_id_p
366 );
367 
383  Objects_APIs the_api,
384  uint16_t the_class
385 );
386 
400  Objects_Id id
401 );
402 
412  const Objects_Information *information
413 )
414 {
415  return information->name_length > 0;
416 }
417 
433  Objects_Id id,
434  size_t length,
435  char *name
436 );
437 
453  Objects_Name name,
454  bool is_string,
455  char *buffer,
456  size_t buffer_size
457 );
458 
473 bool _Objects_Set_name(
474  const Objects_Information *information,
475  Objects_Control *the_object,
476  const char *name
477 );
478 
486  const Objects_Information *information,
487  Objects_Control *the_object
488 )
489 {
490  _Assert( !_Objects_Has_string_name( information ) );
491  the_object->name.name_u32 = 0;
492 }
493 
501  const Objects_Information *information,
502  Objects_Control *the_object
503 );
504 
514 void _Objects_Close(
515  const Objects_Information *information,
516  Objects_Control *the_object
517 );
518 
527  const Objects_Information *information
528 );
529 
538  const Objects_Information *information
539 )
540 {
541  return information->objects_per_block;
542 }
543 
553  uint32_t the_api
554 )
555 {
556  if ( !the_api || the_api > OBJECTS_APIS_LAST )
557  return false;
558  return true;
559 }
560 
571  uint32_t node
572 )
573 {
574  return ( node == _Objects_Local_node );
575 }
576 
588 #if defined(RTEMS_MULTIPROCESSING)
589  Objects_Id id
590 #else
592 #endif
593 )
594 {
595 #if defined(RTEMS_MULTIPROCESSING)
597 #else
598  return true;
599 #endif
600 }
601 
612  Objects_Id left,
613  Objects_Id right
614 )
615 {
616  return ( left == right );
617 }
618 
629 {
630  id &= ~OBJECTS_INDEX_MASK;
632  return id;
633 }
634 
643  const Objects_Information *information
644 )
645 {
646  return _Objects_Get_index( information->maximum_id );
647 }
648 
656  Objects_Information *information
657 )
658 {
659  return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive );
660 }
661 
672  const Objects_Information *information
673 )
674 {
675  return information->objects_per_block != 0;
676 }
677 
693  const Objects_Information *information,
694  uint32_t index,
695  Objects_Control *the_object
696 )
697 {
698  /*
699  * This routine is ONLY to be called from places in the code
700  * where the Id is known to be good. Therefore, this should NOT
701  * occur in normal situations.
702  */
703  _Assert( index >= OBJECTS_INDEX_MINIMUM );
704  _Assert( index <= _Objects_Get_maximum_index( information ) );
705 
706  information->local_table[ index - OBJECTS_INDEX_MINIMUM ] = the_object;
707 }
708 
726  const Objects_Information *information,
727  Objects_Control *the_object
728 )
729 {
730  _Assert( information != NULL );
731  _Assert( the_object != NULL );
732 
734  information,
735  _Objects_Get_index( the_object->id ),
736  NULL
737  );
738 }
739 
751  Objects_Information *information,
752  Objects_Control *the_object,
753  Objects_Name name
754 )
755 {
756  _Assert( information != NULL );
757  _Assert( the_object != NULL );
758 
759  the_object->name = name;
760 
762  information,
763  _Objects_Get_index( the_object->id ),
764  the_object
765  );
766 }
767 
779  const Objects_Information *information,
780  Objects_Control *the_object,
781  uint32_t name
782 )
783 {
784  _Assert( !_Objects_Has_string_name( information ) );
785  the_object->name.name_u32 = name;
786 
788  information,
789  _Objects_Get_index( the_object->id ),
790  the_object
791  );
792 }
793 
805  const Objects_Information *information,
806  Objects_Control *the_object,
807  const char *name
808 )
809 {
810  _Assert( _Objects_Has_string_name( information ) );
811  the_object->name.name_p = name;
812 
814  information,
815  _Objects_Get_index( the_object->id ),
816  the_object
817  );
818 }
819 
835 {
836  _RTEMS_Lock_allocator();
837 }
838 
847 {
848  _RTEMS_Unlock_allocator();
849 }
850 
858 {
859  return _RTEMS_Allocator_is_owner();
860 }
861 
878  Objects_Information *information
879 )
880 {
881  _Assert(
884  );
885 
886  return ( *information->allocate )( information );
887 }
888 
934  Objects_Information *information,
935  Objects_Control *the_object
936 )
937 {
939  _Assert( information->deallocate != NULL );
940  ( *information->deallocate )( information, the_object );
941 }
942 
953  Objects_Information *information,
954  Objects_Control *the_object
955 )
956 {
957  Objects_Maximum objects_per_block;
958  Objects_Maximum block;
959 
960  _Assert( _Objects_Is_auto_extend( information ) );
961 
962  objects_per_block = information->objects_per_block;
963  block = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
964 
965  if ( block > objects_per_block ) {
966  block /= objects_per_block;
967 
968  information->inactive_per_block[ block ]--;
969  information->inactive--;
970  }
971 }
972 
983  Objects_Information *information,
984  void ( *extend )( Objects_Information * )
985 )
986 {
987  Objects_Control *the_object;
988 
989  _Assert( _Objects_Is_auto_extend( information ) );
990 
991  the_object = _Objects_Get_inactive( information );
992 
993  if ( the_object == NULL ) {
994  ( *extend )( information );
995  the_object = _Objects_Get_inactive( information );
996  }
997 
998  if ( the_object != NULL ) {
999  _Objects_Activate_unlimited( information, the_object );
1000  }
1001 
1002  return the_object;
1003 }
1004 
1007 #ifdef __cplusplus
1008 }
1009 #endif
1010 
1011 #if defined(RTEMS_MULTIPROCESSING)
1012 #include <rtems/score/objectmp.h>
1013 #endif
1014 
1015 
1016 #endif
1017 /* end of include file */
static __inline__ Objects_Control * _Objects_Allocate_with_extend(Objects_Information *information, void(*extend)(Objects_Information *))
Allocate an object and extend the objects information on demand.
Definition: objectimpl.h:982
uint32_t name_u32
Definition: object.h:68
static __inline__ void _Objects_Allocator_unlock(void)
Unlocks the object allocator mutex.
Definition: objectimpl.h:846
void _Objects_Shrink_information(Objects_Information *information)
Shrinks an object class information record.
#define OBJECTS_APIS_LAST
Definition: object.h:183
void _Objects_Free_objects_block(Objects_Information *information, Objects_Maximum block)
Free the objects block with the specified index.
static __inline__ bool _Objects_Is_local_id(Objects_Id id RTEMS_UNUSED)
Checks if the id is of a local object.
Definition: objectimpl.h:587
static __inline__ Objects_Maximum _Objects_Get_maximum_index(const Objects_Information *information)
Returns the maximum index of the specified object class.
Definition: objectimpl.h:642
#define _Objects_Maximum_nodes
Definition: objectimpl.h:74
static __inline__ bool _Objects_Is_local_node(uint32_t node)
Checks if the node is of the local object.
Definition: objectimpl.h:570
#define OBJECTS_INDEX_START_BIT
Definition: object.h:92
static __inline__ void _Objects_Activate_unlimited(Objects_Information *information, Objects_Control *the_object)
Activate the object.
Definition: objectimpl.h:952
Objects_Name_or_id_lookup_errors _Objects_Name_to_id_u32(uint32_t name, uint32_t node, Objects_Id *id, const Objects_Information *information)
Searches an object of the specified class with the specified name on the specified set of nodes...
Objects_Information * _Objects_Get_information(Objects_APIs the_api, uint16_t the_class)
Gets object information.
Definition: objectgetinfo.c:23
static __inline__ Objects_Control * _Objects_Allocate_unprotected(Objects_Information *information)
Allocates an object without locking the allocator mutex.
Definition: objectimpl.h:877
static __inline__ bool _System_state_Is_up(System_state_Codes state)
Checks if the state is up.
Definition: sysstate.h:133
Objects_Information **const _Objects_Information_table[OBJECTS_APIS_LAST+1]
void _Objects_Initialize_information(Objects_Information *information)
Initializes the specified objects information.
Objects_Name_or_id_lookup_errors
Definition: objectimpl.h:203
#define OBJECTS_INDEX_MINIMUM
Definition: objectimpl.h:80
Chain_Control Inactive
This is the chain of inactive object control blocks.
Definition: objectdata.h:256
uint16_t Objects_Maximum
Definition: object.h:86
Constants and Structures Related with Thread Dispatch.
Objects_Information * _Objects_Get_information_id(Objects_Id id)
Gets information of an object from an ID.
Objects_Maximum * inactive_per_block
This is the number of inactive object control blocks per allocation block.
Definition: objectdata.h:264
static __inline__ void _Objects_Open_u32(const Objects_Information *information, Objects_Control *the_object, uint32_t name)
Places the_object control pointer and object name in the Local Pointer and Local Name Tables...
Definition: objectimpl.h:778
size_t _Objects_Name_to_string(Objects_Name name, bool is_string, char *buffer, size_t buffer_size)
Converts the specified object name to a text representation.
static __inline__ Objects_Maximum _Objects_Get_index(Objects_Id id)
Returns the index portion of the ID.
Definition: object.h:298
char * _Objects_Get_name_as_string(Objects_Id id, size_t length, char *name)
Gets object name in the form of a C string.
static __inline__ Objects_Control * _Objects_Get_inactive(Objects_Information *information)
Get an inactive object or NULL.
Definition: objectimpl.h:655
bool(* Objects_Name_comparators)(void *, void *, uint16_t)
Definition: objectimpl.h:44
Objects_Maximum _Objects_Extend_information(Objects_Information *information)
Extends an object class information record.
Objects_Control *(* allocate)(Objects_Information *)
Allocate an object.
Definition: objectdata.h:203
Objects_Maximum inactive
This is the number of object control blocks on the inactive chain.
Definition: objectdata.h:222
void(* deallocate)(Objects_Information *, Objects_Control *)
Free an object.
Definition: objectdata.h:213
static __inline__ void _Objects_Allocator_lock(void)
Locks the object allocator mutex.
Definition: objectimpl.h:834
Objects_Control * _Objects_Allocate(Objects_Information *information)
Allocates an object.
Object Handler Data Structures.
Information for the Assert Handler.
Objects_Control * _Objects_Get_by_name(const Objects_Information *information, const char *name, size_t *name_length_p, Objects_Get_by_name_error *error)
Gets an object control block identified by its name.
static __inline__ uint32_t _Objects_Get_node(Objects_Id id)
Returns the node portion of the ID.
Definition: object.h:284
Objects_Id maximum_id
This is the maximum valid ID of this object API class.
Definition: objectdata.h:185
static __inline__ bool _Objects_Has_string_name(const Objects_Information *information)
Returns if the object has a string name.
Definition: objectimpl.h:411
static __inline__ void _Objects_Open(Objects_Information *information, Objects_Control *the_object, Objects_Name name)
Places the_object control pointer and object name in the Local Pointer and Local Name Tables...
Definition: objectimpl.h:750
Objects_Control ** local_table
This points to the table of local object control blocks.
Definition: objectdata.h:195
Objects_Maximum _Objects_Active_count(const Objects_Information *information)
Returns the count of active objects.
static __inline__ void _Objects_Namespace_remove_u32(const Objects_Information *information, Objects_Control *the_object)
Removes object with a 32-bit integer name from its namespace.
Definition: objectimpl.h:485
API Mutex Handler API.
static __inline__ bool _Objects_Allocator_is_owner(void)
Checks if the allocator is the owner of the object allocator mutex.
Definition: objectimpl.h:857
The information structure used to manage each API class of objects.
Definition: objectdata.h:176
static __inline__ void _Objects_Open_string(const Objects_Information *information, Objects_Control *the_object, const char *name)
Places the_object control pointer and object name in the Local Pointer and Local Name Tables...
Definition: objectimpl.h:804
static __inline__ void _Objects_Set_local_object(const Objects_Information *information, uint32_t index, Objects_Control *the_object)
Sets the pointer to the local_table object referenced by the index.
Definition: objectimpl.h:692
bool _Objects_Set_name(const Objects_Information *information, Objects_Control *the_object, const char *name)
Sets objects name.
Objects_Control * _Objects_Get_next(Objects_Id id, const Objects_Information *information, Objects_Id *next_id_p)
Gets the next open object after the specified object identifier.
const char * name_p
Definition: object.h:66
#define RTEMS_UNUSED
Tells the compiler that a specific variable or function is deliberately unused.
Definition: basedefs.h:878
uint16_t name_length
This is the maximum length of names.
Definition: objectdata.h:247
static __inline__ Objects_Maximum _Objects_Extend_size(const Objects_Information *information)
Returns the object&#39;s objects per block.
Definition: objectimpl.h:537
static __inline__ System_state_Codes _System_state_Get(void)
Gets the current system state.
Definition: sysstate.h:90
#define _Objects_Local_node
The local MPCI node number.
Definition: object.h:347
Objects_APIs
Definition: object.h:174
#define OBJECTS_INDEX_MASK
Definition: object.h:114
System State Handler API.
void _Objects_Namespace_remove_string(const Objects_Information *information, Objects_Control *the_object)
Removes object with a string name from its namespace.
uint32_t Objects_Id
Definition: object.h:80
Objects_Control * _Objects_Get(Objects_Id id, ISR_lock_Context *lock_context, const Objects_Information *information)
Maps the specified object identifier to the associated local object control block.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Objects_Name name
Definition: objectdata.h:45
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
Objects_Maximum objects_per_block
This is the number of object control blocks in an allocation block.
Definition: objectdata.h:231
static __inline__ bool _Objects_Is_api_valid(uint32_t the_api)
Checks if the api is valid.
Definition: objectimpl.h:552
static __inline__ Objects_Id _Objects_Get_minimum_id(Objects_Id id)
Returns the identifier with the minimum index for the specified identifier.
Definition: objectimpl.h:628
void _Objects_Close(const Objects_Information *information, Objects_Control *the_object)
Closes object.
Definition: objectclose.c:23
Objects_Control * _Objects_Get_no_protection(Objects_Id id, const Objects_Information *information)
Maps object ids to object control blocks.
ISR Locks.
unsigned int _Objects_API_maximum_class(uint32_t api)
Returns highest numeric value of a valid API for the specified API.
static __inline__ void _Objects_Invalidate_Id(const Objects_Information *information, Objects_Control *the_object)
Invalidates an object Id.
Definition: objectimpl.h:725
static __inline__ Objects_Maximum _Objects_Is_auto_extend(const Objects_Information *information)
Checks if the automatic object extension (unlimited objects) is enabled.
Definition: objectimpl.h:671
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
static __inline__ Chain_Node * _Chain_Get_unprotected(Chain_Control *the_chain)
Gets the first node (unprotected).
Definition: chainimpl.h:630
static __inline__ bool _Objects_Are_ids_equal(Objects_Id left, Objects_Id right)
Checks if two object IDs are equal.
Definition: objectimpl.h:611
static __inline__ void _Objects_Free(Objects_Information *information, Objects_Control *the_object)
Frees an object.
Definition: objectimpl.h:933
Objects_Id id
Definition: objectdata.h:43
Objects_Name_or_id_lookup_errors _Objects_Id_to_name(Objects_Id id, Objects_Name *name)
Returns the name associated with object id.