RTEMS 6.1-rc7
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 _Assert( !_Objects_Has_string_name( information ) );
480 the_object->name.name_u32 = 0;
481}
482
490 const Objects_Information *information,
491 Objects_Control *the_object
492);
493
503void _Objects_Close(
504 const Objects_Information *information,
505 Objects_Control *the_object
506);
507
516 const Objects_Information *information
517);
518
526static inline Objects_Maximum _Objects_Extend_size(
527 const Objects_Information *information
528)
529{
530 return information->objects_per_block;
531}
532
541static inline bool _Objects_Is_api_valid(
542 uint32_t the_api
543)
544{
545 return ( 1 <= the_api && the_api <= OBJECTS_APIS_LAST );
546}
547
557static inline bool _Objects_Is_local_node(
558 uint32_t node
559)
560{
561 return ( node == _Objects_Local_node );
562}
563
574static inline bool _Objects_Is_local_id(
575#if defined(RTEMS_MULTIPROCESSING)
576 Objects_Id id
577#else
579#endif
580)
581{
582#if defined(RTEMS_MULTIPROCESSING)
583 return _Objects_Is_local_node( _Objects_Get_node(id) );
584#else
585 return true;
586#endif
587}
588
598static inline bool _Objects_Are_ids_equal(
599 Objects_Id left,
600 Objects_Id right
601)
602{
603 return ( left == right );
604}
605
615static inline Objects_Id _Objects_Get_minimum_id( Objects_Id id )
616{
617 id &= ~OBJECTS_INDEX_MASK;
619 return id;
620}
621
629static inline Objects_Maximum _Objects_Get_maximum_index(
630 const Objects_Information *information
631)
632{
633 return _Objects_Get_index( information->maximum_id );
634}
635
642static inline Objects_Control *_Objects_Get_inactive(
643 Objects_Information *information
644)
645{
646 return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive );
647}
648
658static inline Objects_Maximum _Objects_Is_auto_extend(
659 const Objects_Information *information
660)
661{
662 return information->objects_per_block != 0;
663}
664
679static inline void _Objects_Set_local_object(
680 const Objects_Information *information,
681 uint32_t index,
682 Objects_Control *the_object
683)
684{
685 /*
686 * This routine is ONLY to be called from places in the code
687 * where the Id is known to be good. Therefore, this should NOT
688 * occur in normal situations.
689 */
690 _Assert( index >= OBJECTS_INDEX_MINIMUM );
691 _Assert( index <= _Objects_Get_maximum_index( information ) );
692
693 information->local_table[ index - OBJECTS_INDEX_MINIMUM ] = the_object;
694}
695
712static inline void _Objects_Invalidate_Id(
713 const Objects_Information *information,
714 Objects_Control *the_object
715)
716{
717 _Assert( information != NULL );
718 _Assert( the_object != NULL );
719
720 _Objects_Set_local_object(
721 information,
722 _Objects_Get_index( the_object->id ),
723 NULL
724 );
725}
726
739static inline Objects_Id _Objects_Open_u32(
740 const Objects_Information *information,
741 Objects_Control *the_object,
742 uint32_t name
743)
744{
745 _Assert( information != NULL );
746 _Assert( !_Objects_Has_string_name( information ) );
747 _Assert( the_object != NULL );
748
749 the_object->name.name_u32 = name;
750
751 _Objects_Set_local_object(
752 information,
753 _Objects_Get_index( the_object->id ),
754 the_object
755 );
756
757 return the_object->id;
758}
759
770static inline void _Objects_Open_string(
771 const Objects_Information *information,
772 Objects_Control *the_object,
773 const char *name
774)
775{
776 _Assert( information != NULL );
777 _Assert( _Objects_Has_string_name( information ) );
778 _Assert( the_object != NULL );
779
780 the_object->name.name_p = name;
781
782 _Objects_Set_local_object(
783 information,
784 _Objects_Get_index( the_object->id ),
785 the_object
786 );
787}
788
803static inline void _Objects_Allocator_lock( void )
804{
805 _RTEMS_Lock_allocator();
806}
807
815static inline void _Objects_Allocator_unlock( void )
816{
817 _RTEMS_Unlock_allocator();
818}
819
826static inline bool _Objects_Allocator_is_owner( void )
827{
828 return _RTEMS_Allocator_is_owner();
829}
830
846static inline Objects_Control *_Objects_Allocate_unprotected(
847 Objects_Information *information
848)
849{
850 _Assert(
851 _Objects_Allocator_is_owner()
852 || !_System_state_Is_up( _System_state_Get() )
853 );
854
855 return ( *information->allocate )( information );
856}
857
902static inline void _Objects_Free(
903 Objects_Information *information,
904 Objects_Control *the_object
905)
906{
907 _Assert( _Objects_Allocator_is_owner() );
908 _Assert( information->deallocate != NULL );
909 ( *information->deallocate )( information, the_object );
910}
911
923static inline bool _Objects_Is_in_allocated_block(
924 Objects_Maximum index,
925 Objects_Maximum objects_per_block
926)
927{
928 return index >= objects_per_block;
929}
930
940static inline void _Objects_Activate_unlimited(
941 Objects_Information *information,
942 Objects_Control *the_object
943)
944{
945 Objects_Maximum objects_per_block;
946 Objects_Maximum index;
947
948 _Assert( _Objects_Is_auto_extend( information ) );
949
950 objects_per_block = information->objects_per_block;
951 index = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
952
953 if ( _Objects_Is_in_allocated_block( index, objects_per_block ) ) {
954 Objects_Maximum block;
955
956 block = index / objects_per_block;
957
958 information->inactive_per_block[ block ]--;
959 information->inactive--;
960 }
961}
962
972static inline Objects_Control *_Objects_Allocate_with_extend(
973 Objects_Information *information,
974 void ( *extend )( Objects_Information * )
975)
976{
977 Objects_Control *the_object;
978
979 _Assert( _Objects_Is_auto_extend( information ) );
980
981 the_object = _Objects_Get_inactive( information );
982
983 if ( the_object == NULL ) {
984 ( *extend )( information );
985 the_object = _Objects_Get_inactive( information );
986 }
987
988 if ( the_object != NULL ) {
989 _Objects_Activate_unlimited( information, the_object );
990 }
991
992 return the_object;
993}
994
1000void _Objects_Free_nothing( void *ptr );
1001
1004#ifdef __cplusplus
1005}
1006#endif
1007
1008#if defined(RTEMS_MULTIPROCESSING)
1009#include <rtems/score/objectmp.h>
1010#endif
1011
1012
1013#endif
1014/* 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:902
#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