From 8b0e752fee90af946e0e117ca7d46a7df7814d14 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 10 Dec 2018 13:44:53 +0100 Subject: score: Remove Objects_Information::auto_extend Use Objects_Information::objects_per_block to provide this information. Add and use _Objects_Is_auto_extend(). Update #3621. --- cpukit/score/src/objectallocate.c | 2 +- cpukit/score/src/objectextendinformation.c | 25 ++++++++++++++----------- cpukit/score/src/objectfree.c | 2 +- cpukit/score/src/objectinitializeinformation.c | 25 +++++++++++++------------ 4 files changed, 29 insertions(+), 25 deletions(-) (limited to 'cpukit/score') diff --git a/cpukit/score/src/objectallocate.c b/cpukit/score/src/objectallocate.c index 2f991477da..9213cf8eb7 100644 --- a/cpukit/score/src/objectallocate.c +++ b/cpukit/score/src/objectallocate.c @@ -56,7 +56,7 @@ Objects_Control *_Objects_Allocate_unprotected( */ the_object = _Objects_Get_inactive( information ); - if ( information->auto_extend ) { + if ( _Objects_Is_auto_extend( information ) ) { /* * If the list is empty then we are out of objects and need to * extend information base. diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c index 4e55bbc636..22b9ec671b 100644 --- a/cpukit/score/src/objectextendinformation.c +++ b/cpukit/score/src/objectextendinformation.c @@ -49,6 +49,7 @@ void _Objects_Extend_information( uint32_t index_base; uint32_t index_end; uint32_t index; + Objects_Maximum extend_count; Objects_Maximum old_maximum; uint32_t new_maximum; size_t object_block_size; @@ -62,7 +63,6 @@ void _Objects_Extend_information( ); api_class_and_node = information->maximum_id & ~OBJECTS_INDEX_MASK; - old_maximum = _Objects_Get_maximum_index( information ); /* * Search for a free block of indexes. If we do NOT need to allocate or @@ -72,22 +72,26 @@ void _Objects_Extend_information( index_base = 0; block = 0; - if ( information->object_blocks == NULL ) + if ( information->object_blocks == NULL ) { + extend_count = _Objects_Get_maximum_index( information ); + old_maximum = 0; block_count = 0; - else { - block_count = old_maximum / information->objects_per_block; + } else { + extend_count = information->objects_per_block; + old_maximum = _Objects_Get_maximum_index( information ); + block_count = old_maximum / extend_count; for ( ; block < block_count; block++ ) { if ( information->object_blocks[ block ] == NULL ) { do_extend = false; break; } else - index_base += information->objects_per_block; + index_base += extend_count; } } - index_end = index_base + information->objects_per_block; - new_maximum = (uint32_t) old_maximum + information->objects_per_block; + new_maximum = (uint32_t) old_maximum + extend_count; + index_end = index_base + extend_count; /* * We need to limit the number of objects to the maximum number @@ -102,9 +106,8 @@ void _Objects_Extend_information( * Allocate the name table, and the objects and if it fails either return or * generate a fatal error depending on auto-extending being active. */ - object_block_size = information->objects_per_block - * information->object_size; - if ( information->auto_extend ) { + object_block_size = extend_count * information->object_size; + if ( _Objects_Is_auto_extend( information ) ) { new_object_block = _Workspace_Allocate( object_block_size ); if ( !new_object_block ) return; @@ -155,7 +158,7 @@ void _Objects_Extend_information( table_size = object_blocks_size + local_table_size + block_count * sizeof( *inactive_per_block ); - if ( information->auto_extend ) { + if ( _Objects_Is_auto_extend( information ) ) { object_blocks = _Workspace_Allocate( table_size ); if ( !object_blocks ) { _Workspace_Free( new_object_block ); diff --git a/cpukit/score/src/objectfree.c b/cpukit/score/src/objectfree.c index cf31a5b24e..38ae17d739 100644 --- a/cpukit/score/src/objectfree.c +++ b/cpukit/score/src/objectfree.c @@ -31,7 +31,7 @@ void _Objects_Free( _Chain_Append_unprotected( &information->Inactive, &the_object->Node ); - if ( information->auto_extend ) { + if ( _Objects_Is_auto_extend( information ) ) { Objects_Maximum objects_per_block; Objects_Maximum block; Objects_Maximum inactive; diff --git a/cpukit/score/src/objectinitializeinformation.c b/cpukit/score/src/objectinitializeinformation.c index d51d5cfca6..57e588ad4a 100644 --- a/cpukit/score/src/objectinitializeinformation.c +++ b/cpukit/score/src/objectinitializeinformation.c @@ -39,11 +39,12 @@ void _Objects_Do_initialize_information( { Objects_Maximum maximum_per_allocation; + maximum_per_allocation = _Objects_Maximum_per_allocation( maximum ); information->maximum_id = _Objects_Build_id( the_api, the_class, _Objects_Local_node, - 0 + maximum_per_allocation ); information->object_size = object_size; @@ -55,20 +56,20 @@ void _Objects_Do_initialize_information( /* * Are we operating in limited or unlimited (e.g. auto-extend) mode. */ - information->auto_extend = _Objects_Is_unlimited( maximum ); - maximum_per_allocation = _Objects_Maximum_per_allocation( maximum ); + if ( _Objects_Is_unlimited( maximum ) ) { + /* + * Unlimited and maximum of zero is illogical. + */ + if ( maximum_per_allocation == 0) { + _Internal_error( INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0 ); + } - /* - * Unlimited and maximum of zero is illogical. - */ - if ( information->auto_extend && maximum_per_allocation == 0) { - _Internal_error( INTERNAL_ERROR_UNLIMITED_AND_MAXIMUM_IS_0 ); + /* + * The allocation unit is the maximum value + */ + information->objects_per_block = maximum_per_allocation; } - /* - * The allocation unit is the maximum value - */ - information->objects_per_block = maximum_per_allocation; /* * Calculate the maximum name length -- cgit v1.2.3