RTEMS 7.0-rc1
Loading...
Searching...
No Matches
objectimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (c) 1989-2011.
14 * On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _RTEMS_SCORE_OBJECTIMPL_H
39#define _RTEMS_SCORE_OBJECTIMPL_H
40
43#include <rtems/score/assert.h>
44#include <rtems/score/isrlock.h>
45#include <rtems/score/status.h>
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
63 void * /* name_1 */,
64 void * /* name_2 */,
65 uint16_t /* length */
66);
67
69#define OBJECTS_INTERNAL_CLASSES_LAST OBJECTS_INTERNAL_THREADS
70
72#define OBJECTS_RTEMS_CLASSES_LAST OBJECTS_RTEMS_BARRIERS
73
75#define OBJECTS_POSIX_CLASSES_LAST OBJECTS_POSIX_SHMS
76
77/*
78 * For fake objects, which have an object identifier, but no objects
79 * information block.
80 */
81typedef enum {
82 OBJECTS_FAKE_OBJECTS_NO_CLASS = 0,
83 OBJECTS_FAKE_OBJECTS_SCHEDULERS = 1
84} Objects_Fake_objects_API;
85
89#if defined(RTEMS_MULTIPROCESSING)
90extern uint16_t _Objects_Maximum_nodes;
91#else
92#define _Objects_Maximum_nodes 1
93#endif
94
98#define OBJECTS_INDEX_MINIMUM 1U
99
105extern Objects_Information ** const
107
117 Objects_Information *information
118);
119
127 Objects_Information *information,
128 Objects_Maximum block
129);
130
142 Objects_Information *information
143);
144
154
166unsigned int _Objects_API_maximum_class(
167 uint32_t api
168);
169
210
231 uint32_t name,
232 uint32_t node,
233 Objects_Id *id,
234 const Objects_Information *information
235);
236
237typedef enum {
238 OBJECTS_GET_BY_NAME_INVALID_NAME,
239 OBJECTS_GET_BY_NAME_NAME_TOO_LONG,
240 OBJECTS_GET_BY_NAME_NO_OBJECT
241} Objects_Get_by_name_error;
242
258 const Objects_Information *information,
259 const char *name,
260 size_t *name_length_p,
261 Objects_Get_by_name_error *error
262);
263
281 Objects_Id id,
282 Objects_Name *name
283);
284
306 Objects_Id id,
307 ISR_lock_Context *lock_context,
308 const Objects_Information *information
309);
310
332 Objects_Id id,
333 const Objects_Information *information
334);
335
351 Objects_Id id,
352 const Objects_Information *information,
353 Objects_Id *next_id_p
354);
355
371 Objects_APIs the_api,
372 uint16_t the_class
373);
374
388 Objects_Id id
389);
390
399static inline bool _Objects_Has_string_name(
400 const Objects_Information *information
401)
402{
403 return information->name_length > 0;
404}
405
421 Objects_Id id,
422 size_t length,
423 char *name
424);
425
441 Objects_Name name,
442 bool is_string,
443 char *buffer,
444 size_t buffer_size
445);
446
463 const Objects_Information *information,
464 Objects_Control *the_object,
465 const char *name
466);
467
474static inline void _Objects_Namespace_remove_u32(
475 const Objects_Information *information,
476 Objects_Control *the_object
477)
478{
479 (void) information;
480
481 _Assert( !_Objects_Has_string_name( information ) );
482 the_object->name.name_u32 = 0;
483}
484
492 const Objects_Information *information,
493 Objects_Control *the_object
494);
495
505void _Objects_Close(
506 const Objects_Information *information,
507 Objects_Control *the_object
508);
509
518 const Objects_Information *information
519);
520
528static inline Objects_Maximum _Objects_Extend_size(
529 const Objects_Information *information
530)
531{
532 return information->objects_per_block;
533}
534
543static inline bool _Objects_Is_api_valid(
544 uint32_t the_api
545)
546{
547 return ( 1 <= the_api && the_api <= OBJECTS_APIS_LAST );
548}
549
559static inline bool _Objects_Is_local_node(
560 uint32_t node
561)
562{
563 return ( node == _Objects_Local_node );
564}
565
576static inline bool _Objects_Is_local_id(
577#if defined(RTEMS_MULTIPROCESSING)
578 Objects_Id id
579#else
581#endif
582)
583{
584#if defined(RTEMS_MULTIPROCESSING)
585 return _Objects_Is_local_node( _Objects_Get_node(id) );
586#else
587 return true;
588#endif
589}
590
600static inline bool _Objects_Are_ids_equal(
601 Objects_Id left,
602 Objects_Id right
603)
604{
605 return ( left == right );
606}
607
617static inline Objects_Id _Objects_Get_minimum_id( Objects_Id id )
618{
619 id &= ~OBJECTS_INDEX_MASK;
621 return id;
622}
623
631static inline Objects_Maximum _Objects_Get_maximum_index(
632 const Objects_Information *information
633)
634{
635 return _Objects_Get_index( information->maximum_id );
636}
637
644static inline Objects_Control *_Objects_Get_inactive(
645 Objects_Information *information
646)
647{
648 return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive );
649}
650
660static inline Objects_Maximum _Objects_Is_auto_extend(
661 const Objects_Information *information
662)
663{
664 return information->objects_per_block != 0;
665}
666
681static inline void _Objects_Set_local_object(
682 const Objects_Information *information,
683 uint32_t index,
684 Objects_Control *the_object
685)
686{
687 /*
688 * This routine is ONLY to be called from places in the code
689 * where the Id is known to be good. Therefore, this should NOT
690 * occur in normal situations.
691 */
692 _Assert( index >= OBJECTS_INDEX_MINIMUM );
693 _Assert( index <= _Objects_Get_maximum_index( information ) );
694
695 information->local_table[ index - OBJECTS_INDEX_MINIMUM ] = the_object;
696}
697
714static inline void _Objects_Invalidate_Id(
715 const Objects_Information *information,
716 Objects_Control *the_object
717)
718{
719 _Assert( information != NULL );
720 _Assert( the_object != NULL );
721
722 _Objects_Set_local_object(
723 information,
724 _Objects_Get_index( the_object->id ),
725 NULL
726 );
727}
728
741static inline Objects_Id _Objects_Open_u32(
742 const Objects_Information *information,
743 Objects_Control *the_object,
744 uint32_t name
745)
746{
747 _Assert( information != NULL );
748 _Assert( !_Objects_Has_string_name( information ) );
749 _Assert( the_object != NULL );
750
751 the_object->name.name_u32 = name;
752
753 _Objects_Set_local_object(
754 information,
755 _Objects_Get_index( the_object->id ),
756 the_object
757 );
758
759 return the_object->id;
760}
761
772static inline void _Objects_Open_string(
773 const Objects_Information *information,
774 Objects_Control *the_object,
775 const char *name
776)
777{
778 _Assert( information != NULL );
779 _Assert( _Objects_Has_string_name( information ) );
780 _Assert( the_object != NULL );
781
782 the_object->name.name_p = name;
783
784 _Objects_Set_local_object(
785 information,
786 _Objects_Get_index( the_object->id ),
787 the_object
788 );
789}
790
805static inline void _Objects_Allocator_lock( void )
806{
807 _RTEMS_Lock_allocator();
808}
809
817static inline void _Objects_Allocator_unlock( void )
818{
819 _RTEMS_Unlock_allocator();
820}
821
828static inline bool _Objects_Allocator_is_owner( void )
829{
830 return _RTEMS_Allocator_is_owner();
831}
832
848static inline Objects_Control *_Objects_Allocate_unprotected(
849 Objects_Information *information
850)
851{
852 _Assert(
853 _Objects_Allocator_is_owner()
854 || !_System_state_Is_up( _System_state_Get() )
855 );
856
857 return ( *information->allocate )( information );
858}
859
904static inline void _Objects_Free(
905 Objects_Information *information,
906 Objects_Control *the_object
907)
908{
909 _Assert( _Objects_Allocator_is_owner() );
910 _Assert( information->deallocate != NULL );
911 ( *information->deallocate )( information, the_object );
912}
913
925static inline bool _Objects_Is_in_allocated_block(
926 Objects_Maximum index,
927 Objects_Maximum objects_per_block
928)
929{
930 return index >= objects_per_block;
931}
932
942static inline void _Objects_Activate_unlimited(
943 Objects_Information *information,
944 Objects_Control *the_object
945)
946{
947 Objects_Maximum objects_per_block;
948 Objects_Maximum index;
949
950 _Assert( _Objects_Is_auto_extend( information ) );
951
952 objects_per_block = information->objects_per_block;
953 index = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
954
955 if ( _Objects_Is_in_allocated_block( index, objects_per_block ) ) {
956 Objects_Maximum block;
957
958 block = index / objects_per_block;
959
960 information->inactive_per_block[ block ]--;
961 information->inactive--;
962 }
963}
964
974static inline Objects_Control *_Objects_Allocate_with_extend(
975 Objects_Information *information,
976 void ( *extend )( Objects_Information * )
977)
978{
979 Objects_Control *the_object;
980
981 _Assert( _Objects_Is_auto_extend( information ) );
982
983 the_object = _Objects_Get_inactive( information );
984
985 if ( the_object == NULL ) {
986 ( *extend )( information );
987 the_object = _Objects_Get_inactive( information );
988 }
989
990 if ( the_object != NULL ) {
991 _Objects_Activate_unlimited( information, the_object );
992 }
993
994 return the_object;
995}
996
1002void _Objects_Free_nothing( void *ptr );
1003
1006#ifdef __cplusplus
1007}
1008#endif
1009
1010#if defined(RTEMS_MULTIPROCESSING)
1011#include <rtems/score/objectmp.h>
1012#endif
1013
1014
1015#endif
1016/* end of include file */
This header file provides the interfaces of the API Mutex Handler.
This header file provides the interfaces of the Assert Handler.
#define RTEMS_UNUSED
Tells the compiler that the variable or function is deliberately unused.
Definition: basedefs.h:927
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
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.
Definition: objectnametoidstring.c:46
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.
Definition: objectgetnameasstring.c:56
unsigned int _Objects_API_maximum_class(uint32_t api)
Returns highest numeric value of a valid API for the specified API.
Definition: objectapimaximumclass.c:44
void _Objects_Shrink_information(Objects_Information *information)
Shrinks an object class information record.
Definition: objectshrinkinformation.c:99
#define OBJECTS_APIS_LAST
Definition: object.h:204
Objects_APIs
Definition: object.h:195
Status_Control _Objects_Set_name(const Objects_Information *information, Objects_Control *the_object, const char *name)
Sets objects name.
Definition: objectsetname.c:47
Objects_Control * _Objects_Allocate(Objects_Information *information)
Allocates an object.
Definition: objectallocate.c:43
Objects_Information **const _Objects_Information_table[OBJECTS_APIS_LAST+1]
Objects_Maximum _Objects_Active_count(const Objects_Information *information)
Returns the count of active objects.
Definition: objectactivecount.c:45
void _Objects_Close(const Objects_Information *information, Objects_Control *the_object)
Closes object.
Definition: objectclose.c:44
void _Objects_Free_objects_block(Objects_Information *information, Objects_Maximum block)
Free the objects block with the specified index.
Definition: objectshrinkinformation.c:47
uint32_t Objects_Id
Definition: object.h:101
bool(* Objects_Name_comparators)(void *, void *, uint16_t)
Definition: objectimpl.h:62
Objects_Control * _Objects_Get_no_protection(Objects_Id id, const Objects_Information *information)
Maps object ids to object control blocks.
Definition: objectgetnoprotection.c:44
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.
Definition: objectgetlocal.c:43
#define OBJECTS_INDEX_START_BIT
Definition: object.h:113
Objects_Information * _Objects_Get_information_id(Objects_Id id)
Gets information of an object from an ID.
Definition: objectgetinfoid.c:44
#define OBJECTS_INDEX_MINIMUM
Definition: objectimpl.h:98
#define _Objects_Maximum_nodes
Definition: objectimpl.h:92
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.
Definition: objectgetnext.c:44
void _Objects_Initialize_information(Objects_Information *information)
Initializes the specified objects information.
Definition: objectinitializeinformation.c:47
void _Objects_Namespace_remove_string(const Objects_Information *information, Objects_Control *the_object)
Removes object with a string name from its namespace.
Definition: objectnamespaceremove.c:45
Status_Control _Objects_Id_to_name(Objects_Id id, Objects_Name *name)
Returns the name associated with object id.
Definition: objectidtoname.c:44
uint16_t Objects_Maximum
Definition: object.h:107
Status_Control _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.
Definition: objectnametoid.c:49
char * _Objects_Get_name_as_string(Objects_Id id, size_t length, char *name)
Gets object name in the form of a C string.
Definition: objectgetnameasstring.c:107
Objects_Information * _Objects_Get_information(Objects_APIs the_api, uint16_t the_class)
Gets object information.
Definition: objectgetinfo.c:44
void _Objects_Free_nothing(void *ptr)
This function does nothing.
Definition: objectfreenothing.c:43
Objects_Maximum _Objects_Extend_information(Objects_Information *information)
Extends an object class information record.
Definition: objectextendinformation.c:52
#define _Objects_Local_node
The local MPCI node number.
Definition: object.h:368
Status_Control
Status codes.
Definition: status.h:111
This header file provides the interfaces of the ISR Locks.
This header file provides data structures used by the implementation and the Application Configuratio...
This header file provides the interfaces of the Object Handler Multiprocessing (MP) Support.
This header file provides the interfaces of the Operation Status Support.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:94
Definition: objectdata.h:61
Objects_Id id
Definition: objectdata.h:65
Objects_Name name
Definition: objectdata.h:67
The information structure used to manage each API class of objects.
Definition: objectdata.h:198
Objects_Id maximum_id
This is the maximum valid ID of this object API class.
Definition: objectdata.h:207
Objects_Control ** local_table
This points to the table of local object control blocks.
Definition: objectdata.h:217
Chain_Control Inactive
This is the chain of inactive object control blocks.
Definition: objectdata.h:278
Objects_Maximum inactive
This is the number of object control blocks on the inactive chain.
Definition: objectdata.h:244
Objects_Maximum * inactive_per_block
This is the number of inactive object control blocks per allocation block.
Definition: objectdata.h:286
uint16_t name_length
This is the maximum length of names.
Definition: objectdata.h:269
Objects_Maximum objects_per_block
This is the number of object control blocks in an allocation block.
Definition: objectdata.h:253
Objects_Control *(* allocate)(Objects_Information *)
Allocate an object.
Definition: objectdata.h:225
void(* deallocate)(Objects_Information *, Objects_Control *)
Free an object.
Definition: objectdata.h:235
This header file provides the interfaces of the System State Handler.
This header file provides the interfaces of the Thread Handler related to thread dispatching.
Definition: object.h:85
const char * name_p
Definition: object.h:87
uint32_t name_u32
Definition: object.h:89