From 3235ad9a2cd717df901853ad5220a4aaffae84a9 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 23 Aug 1995 19:30:23 +0000 Subject: Support for variable length names added to Object Handler. This supports both fixed length "raw" names and strings from the API's point of view. Both inline and macro implementations were tested. --- cpukit/score/include/rtems/score/object.h | 142 +++++++++++------- cpukit/score/include/rtems/score/objectmp.h | 5 +- cpukit/score/include/rtems/system.h | 6 + cpukit/score/inline/rtems/score/object.inl | 45 +----- cpukit/score/macros/rtems/score/object.inl | 33 +---- cpukit/score/src/object.c | 216 ++++++++++++++++++++++++---- cpukit/score/src/objectmp.c | 7 +- cpukit/score/src/thread.c | 12 +- 8 files changed, 313 insertions(+), 153 deletions(-) (limited to 'cpukit/score') diff --git a/cpukit/score/include/rtems/score/object.h b/cpukit/score/include/rtems/score/object.h index 7f4c01c53d..c5226302d6 100644 --- a/cpukit/score/include/rtems/score/object.h +++ b/cpukit/score/include/rtems/score/object.h @@ -29,7 +29,25 @@ extern "C" { * object names. */ -typedef unsigned32 Objects_Name; +typedef void * Objects_Name; + +/* + * Space for object names is allocated in multiples of this. + * + * NOTE: Must be a power of 2. Matches the name manipulation routines. + */ + +#define OBJECTS_NAME_ALIGNMENT 4 + +/* + * Functions which compare names are prototyped like this. + */ + +typedef boolean (*Objects_Name_comparators)( + void * /* name_1 */, + void * /* name_2 */, + unsigned32 /* length */ +); /* * The following type defines the control block used to manage @@ -91,7 +109,7 @@ typedef enum { typedef struct { Chain_Node Node; Objects_Id id; - Objects_Name *name; + Objects_Name name; } Objects_Control; /* @@ -108,6 +126,8 @@ typedef struct { Objects_Name *name_table; /* table of local object names */ Chain_Control *global_table; /* pointer to global table */ Chain_Control Inactive; /* chain of inactive ctl blocks */ + boolean is_string; /* TRUE if names are strings */ + unsigned32 name_length; /* maximum length of names */ } Objects_Information; /* @@ -179,9 +199,78 @@ void _Objects_Initialize_information ( Objects_Classes the_class, boolean supports_global, unsigned32 maximum, - unsigned32 size + unsigned32 size, + boolean is_string, + unsigned32 maximum_name_length +); + +/* + * _Objects_Clear_name + * + * DESCRIPTION: + * + * XXX + */ + +void _Objects_Clear_name( + void *name, + unsigned32 length +); + +/* + * _Objects_Copy_name_string + * + * DESCRIPTION: + * + * XXX + */ + +void _Objects_Copy_name_string( + void *source, + void *destination +); + +/* + * _Objects_Copy_name_raw + * + * DESCRIPTION: + * + * XXX + */ + +void _Objects_Copy_name_raw( + void *source, + void *destination, + unsigned32 length +); + +/* + * _Objects_Compare_name_string + * + * DESCRIPTION: + * + * XXX + */ + +boolean _Objects_Compare_name_string( + void *name_1, + void *name_2, + unsigned32 length ); +/* + * _Objects_Compare_name_raw + * + * DESCRIPTION: + * + * XXX + */ + +boolean _Objects_Compare_name_raw( + void *name_1, + void *name_2, + unsigned32 length +); /* * _Objects_Name_to_id * @@ -243,53 +332,6 @@ Objects_Control *_Objects_Get_next( Objects_Id *next_id_p ); -/* - * _Objects_Is_name_valid - * - * DESCRIPTION: - * - * This function returns TRUE if the name is valid, and FALSE otherwise. - */ - -STATIC INLINE boolean _Objects_Is_name_valid ( - Objects_Name name -); - -/* - * rtems_build_name - * - * DESCRIPTION: - * - * This function returns an object name composed of the four characters - * C1, C2, C3, and C4. - * - * NOTE: - * - * This must be implemented as a macro for use in Configuration Tables. - * - */ - -#define rtems_build_name( _C1, _C2, _C3, _C4 ) \ - ( (_C1) << 24 | (_C2) << 16 | (_C3) << 8 | (_C4) ) - -/* - * rtems_name_to_characters - * - * DESCRIPTION: - * - * This function breaks the object name into the four component - * characters C1, C2, C3, and C4. - * - */ - -STATIC INLINE void rtems_name_to_characters( - Objects_Name name, - char *c1, - char *c2, - char *c3, - char *c4 -); - /* * _Objects_Build_id * diff --git a/cpukit/score/include/rtems/score/objectmp.h b/cpukit/score/include/rtems/score/objectmp.h index 0d29fda753..6ec5ed1781 100644 --- a/cpukit/score/include/rtems/score/objectmp.h +++ b/cpukit/score/include/rtems/score/objectmp.h @@ -28,7 +28,8 @@ extern "C" { typedef struct { Objects_Control Object; - Objects_Name name; + unsigned32 name; /* XXX broken but works */ + /* XXX If any API is MP with variable length names .. BOOM!!!! */ } Objects_MP_Control; /* @@ -93,7 +94,7 @@ STATIC INLINE boolean _Objects_MP_Is_null_global_object ( boolean _Objects_MP_Open ( Objects_Information *information, - Objects_Name the_name, + unsigned32 the_name, /* XXX -- wrong for variable length */ Objects_Id the_id, boolean is_fatal_error ); diff --git a/cpukit/score/include/rtems/system.h b/cpukit/score/include/rtems/system.h index 96b0abfff8..5f627c1a7c 100644 --- a/cpukit/score/include/rtems/system.h +++ b/cpukit/score/include/rtems/system.h @@ -127,6 +127,12 @@ extern const void * _Entry_points[ RTEMS_NUMBER_OF_ENTRY_POINTS ]; EXTERN rtems_cpu_table _CPU_Table; /* CPU dependent info */ +/* + * XXX weird RTEMS stuff + */ + +#define RTEMS_MAXIMUM_NAME_LENGTH 4 + #ifdef __cplusplus } #endif diff --git a/cpukit/score/inline/rtems/score/object.inl b/cpukit/score/inline/rtems/score/object.inl index da65807aa1..687ffd923b 100644 --- a/cpukit/score/inline/rtems/score/object.inl +++ b/cpukit/score/inline/rtems/score/object.inl @@ -17,39 +17,6 @@ #ifndef __OBJECTS_inl #define __OBJECTS_inl -/*PAGE - * - * _Objects_Is_name_valid - * - */ - -STATIC INLINE boolean _Objects_Is_name_valid ( - Objects_Name name -) -{ - return ( name != 0 ); -} - -/*PAGE - * - * rtems_name_to_characters - * - */ - -STATIC INLINE void rtems_name_to_characters( - Objects_Name name, - char *c1, - char *c2, - char *c3, - char *c4 -) -{ - *c1 = (name >> 24) & 0xff; - *c2 = (name >> 16) & 0xff; - *c3 = (name >> 8) & 0xff; - *c4 = name & 0xff; -} - /*PAGE * * _Objects_Build_id @@ -186,12 +153,15 @@ STATIC INLINE void _Objects_Open( Objects_Name name ) { - unsigned32 index; + unsigned32 index; index = rtems_get_index( the_object->id ); information->local_table[ index ] = the_object; - information->name_table[ index ] = name; - the_object->name = &information->name_table[ index ]; + + if ( information->is_string ) + _Objects_Copy_name_string( name, the_object->name ); + else + _Objects_Copy_name_raw( name, the_object->name, information->name_length ); } /*PAGE @@ -209,8 +179,7 @@ STATIC INLINE void _Objects_Close( index = rtems_get_index( the_object->id ); information->local_table[ index ] = NULL; - information->name_table[ index ] = 0; - the_object->name = 0; + _Objects_Clear_name( the_object->name, information->name_length ); } #endif diff --git a/cpukit/score/macros/rtems/score/object.inl b/cpukit/score/macros/rtems/score/object.inl index 6c7caa383a..27675b19bf 100644 --- a/cpukit/score/macros/rtems/score/object.inl +++ b/cpukit/score/macros/rtems/score/object.inl @@ -17,28 +17,6 @@ #ifndef __OBJECTS_inl #define __OBJECTS_inl -/*PAGE - * - * _Objects_Is_name_valid - * - */ - -#define _Objects_Is_name_valid( _name ) \ - ( (_name) != 0 ) - -/* - * rtems_name_to_characters - * - */ - -#define rtems_name_to_characters( _name, _c1, _c2, _c3, _c4 ) \ - { \ - (*(_c1) = ((_name) >> 24) & 0xff; \ - (*(_c2) = ((_name) >> 16) & 0xff; \ - (*(_c3) = ((_name) >> 8) & 0xff; \ - (*(_c4) = ((_name)) & 0xff; \ - } - /*PAGE * * _Objects_Build_id @@ -134,8 +112,12 @@ \ _index = rtems_get_index( (_the_object)->id ); \ (_information)->local_table[ _index ] = (_the_object); \ - (_information)->name_table[ _index ] = (_name); \ - (_the_object)->name = &(_information)->name_table[ _index ]; \ + \ + if ( (_information)->is_string ) \ + _Objects_Copy_name_string( (_name), (_the_object)->name ); \ + else \ + _Objects_Copy_name_raw( \ + (_name), (_the_object)->name, (_information)->name_length ); \ } /*PAGE @@ -150,8 +132,7 @@ \ _index = rtems_get_index( (_the_object)->id ); \ (_information)->local_table[ _index ] = NULL; \ - (_information)->name_table[ _index ] = 0; \ - (_the_object)->name = 0; \ + _Objects_Clear_name( (_the_object)->name, (_information)->name_length ); \ } #endif diff --git a/cpukit/score/src/object.c b/cpukit/score/src/object.c index 0181903647..5b64ea8802 100644 --- a/cpukit/score/src/object.c +++ b/cpukit/score/src/object.c @@ -55,6 +55,7 @@ void _Objects_Handler_initialization( * the_class - object class * supports_global - TRUE if this is a global object class * maximum - maximum objects of this class + * is_string - TRUE if names for this object are strings * size - size of this object's control block * * Output parameters: NONE @@ -65,15 +66,24 @@ void _Objects_Initialize_information( Objects_Classes the_class, boolean supports_global, unsigned32 maximum, - unsigned32 size + unsigned32 size, + boolean is_string, + unsigned32 maximum_name_length ) { unsigned32 minimum_index; unsigned32 index; Objects_Control *the_object; + unsigned32 name_length; + void *name_area; information->maximum = maximum; information->the_class = the_class; + information->is_string = is_string; + + /* + * Calculate minimum and maximum Id's + */ if ( maximum == 0 ) minimum_index = 0; else minimum_index = 1; @@ -84,24 +94,45 @@ void _Objects_Initialize_information( information->maximum_id = _Objects_Build_id( the_class, _Objects_Local_node, maximum ); + /* + * Allocate local pointer table + */ + information->local_table = _Workspace_Allocate_or_fatal_error( (maximum + 1) * sizeof(Objects_Control *) ); - information->name_table = _Workspace_Allocate_or_fatal_error( - (maximum + 1) * sizeof(Objects_Name) - ); + /* + * Allocate name table + */ + + name_length = maximum_name_length; + + if (name_length & (OBJECTS_NAME_ALIGNMENT-1)) + name_length = (name_length + OBJECTS_NAME_ALIGNMENT) & + ~(OBJECTS_NAME_ALIGNMENT-1); + + information->name_length = name_length; + + name_area = _Workspace_Allocate_or_fatal_error( (maximum + 1) * name_length ); + information->name_table = name_area; + + /* + * Initialize local pointer table + */ - for ( index=0 ; index < maximum ; index++ ) { + for ( index=0 ; index <= maximum ; index++ ) { information->local_table[ index ] = NULL; - information->name_table[ index ] = 0; } + /* + * Initialize objects .. if there are any + */ + if ( maximum == 0 ) { _Chain_Initialize_empty( &information->Inactive ); } else { - _Chain_Initialize( &information->Inactive, _Workspace_Allocate_or_fatal_error( maximum * size ), @@ -110,31 +141,151 @@ void _Objects_Initialize_information( ); the_object = (Objects_Control *) information->Inactive.first; - for ( index=1; - index <= maximum ; - index++ ) { + for ( index=1; index <= maximum ; index++ ) { the_object->id = _Objects_Build_id( the_class, _Objects_Local_node, index ); + + the_object->name = (void *) name_area; + + name_area = _Addresses_Add_offset( name_area, name_length ); + the_object = (Objects_Control *) the_object->Node.next; } } - if ( supports_global == TRUE && _Configuration_Is_multiprocessing() ) { + /* + * Take care of multiprocessing + */ - information->global_table = _Workspace_Allocate_or_fatal_error( - (_Configuration_MP_table->maximum_nodes + 1) * sizeof(Chain_Control) - ); + if ( supports_global == TRUE && _Configuration_Is_multiprocessing() ) { - for ( index=1; - index <= _Configuration_MP_table->maximum_nodes ; - index++ ) - _Chain_Initialize_empty( &information->global_table[ index ] ); - } - else - information->global_table = NULL; + information->global_table = _Workspace_Allocate_or_fatal_error( + (_Configuration_MP_table->maximum_nodes + 1) * sizeof(Chain_Control) + ); + + for ( index=1; + index <= _Configuration_MP_table->maximum_nodes ; + index++ ) + _Chain_Initialize_empty( &information->global_table[ index ] ); + } + else + information->global_table = NULL; +} + +/*PAGE + * + * _Objects_Clear_name + * + * XXX + */ + +void _Objects_Clear_name( + void *name, + unsigned32 length +) +{ + unsigned32 index; + unsigned32 maximum = length / OBJECTS_NAME_ALIGNMENT; + unsigned32 *name_ptr = name; + + for ( index=0 ; index < maximum ; index++ ) + *name_ptr++ = 0; +} + +/*PAGE + * + * _Objects_Copy_name_string + * + * XXX + */ + +void _Objects_Copy_name_string( + void *source, + void *destination +) +{ + unsigned8 *source_p = source; + unsigned8 *destination_p = destination; + + do { + *destination_p++ = *source_p; + } while ( *source_p++ ); +} + +/*PAGE + * + * _Objects_Copy_name_raw + * + * XXX + */ + +void _Objects_Copy_name_raw( + void *source, + void *destination, + unsigned32 length +) +{ + unsigned32 *source_p = source; + unsigned32 *destination_p = destination; + unsigned32 tmp_length = length / OBJECTS_NAME_ALIGNMENT; + + while ( tmp_length-- ) + *destination_p++ = *source_p++; +} + +/*PAGE + * + * _Objects_Compare_name_string + * + * XXX + */ + +boolean _Objects_Compare_name_string( + void *name_1, + void *name_2, + unsigned32 length +) +{ + unsigned8 *name_1_p = name_1; + unsigned8 *name_2_p = name_2; + unsigned32 tmp_length = length; + + do { + if ( *name_1_p++ != *name_2_p++ ) + return FALSE; + if ( !tmp_length-- ) + return FALSE; + } while ( *name_1_p ); + + return TRUE; +} + +/*PAGE + * + * _Objects_Compare_name_raw + * + * XXX + */ + +boolean _Objects_Compare_name_raw( + void *name_1, + void *name_2, + unsigned32 length +) +{ + unsigned32 *name_1_p = name_1; + unsigned32 *name_2_p = name_2; + unsigned32 tmp_length = length / OBJECTS_NAME_ALIGNMENT; + + while ( tmp_length-- ) + if ( *name_1_p++ != *name_2_p++ ) + return FALSE; + + return TRUE; } + /*PAGE * * _Objects_Name_to_id @@ -156,15 +307,17 @@ void _Objects_Initialize_information( rtems_status_code _Objects_Name_to_id( Objects_Information *information, - Objects_Name name, - unsigned32 node, - Objects_Id *id + Objects_Name name, + unsigned32 node, + Objects_Id *id ) { - boolean search_local_node; - Objects_Control **objects; - Objects_Control *the_object; - unsigned32 index; + boolean search_local_node; + Objects_Control **objects; + Objects_Control *the_object; + unsigned32 index; + unsigned32 name_length; + Objects_Name_comparators compare_them; if ( name == 0 ) return( RTEMS_INVALID_NAME ); @@ -179,6 +332,11 @@ rtems_status_code _Objects_Name_to_id( if ( search_local_node ) { objects = information->local_table; + name_length = information->name_length; + + if ( information->is_string ) compare_them = _Objects_Compare_name_string; + else compare_them = _Objects_Compare_name_raw; + for ( index = 1; index <= information->maximum; index++ ) { the_object = objects[ index ]; @@ -186,7 +344,7 @@ rtems_status_code _Objects_Name_to_id( if ( !the_object || !the_object->name ) continue; - if ( name == *the_object->name ) { + if ( (*compare_them)( name, the_object->name, name_length ) ) { *id = the_object->id; return( RTEMS_SUCCESSFUL ); } diff --git a/cpukit/score/src/objectmp.c b/cpukit/score/src/objectmp.c index d75a34b150..a8b067020d 100644 --- a/cpukit/score/src/objectmp.c +++ b/cpukit/score/src/objectmp.c @@ -53,12 +53,12 @@ void _Objects_MP_Handler_initialization ( boolean _Objects_MP_Open ( Objects_Information *information, - Objects_Name the_name, + unsigned32 the_name, /* XXX -- wrong for variable */ Objects_Id the_id, boolean is_fatal_error ) { - Objects_MP_Control *the_global_object; + Objects_MP_Control *the_global_object; the_global_object = _Objects_MP_Allocate_global_object(); if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { @@ -139,6 +139,7 @@ rtems_status_code _Objects_MP_Global_name_search ( Chain_Control *the_chain; Chain_Node *the_node; Objects_MP_Control *the_object; + unsigned32 name_to_use = *(unsigned32 *)the_name; /* XXX variable */ if ( nodes_to_search > _Configuration_MP_table->maximum_nodes ) @@ -174,7 +175,7 @@ rtems_status_code _Objects_MP_Global_name_search ( the_object = (Objects_MP_Control *) the_node; - if ( the_object->name == the_name ) { + if ( the_object->name == name_to_use ) { *the_id = the_object->Object.id; _Thread_Enable_dispatch(); return ( RTEMS_SUCCESSFUL ); diff --git a/cpukit/score/src/thread.c b/cpukit/score/src/thread.c index 92c882d749..9793792b44 100644 --- a/cpukit/score/src/thread.c +++ b/cpukit/score/src/thread.c @@ -58,11 +58,13 @@ void _Thread_Handler_initialization( _Thread_Ticks_per_timeslice = ticks_per_timeslice; _Objects_Initialize_information( - &_Thread_Information, - OBJECTS_RTEMS_TASKS, - TRUE, - maximum_tasks, - sizeof( Thread_Control ) + &_Thread_Information, + OBJECTS_RTEMS_TASKS, + TRUE, + maximum_tasks, + sizeof( Thread_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH ); _Thread_Ready_chain = _Workspace_Allocate_or_fatal_error( -- cgit v1.2.3