score: Simplify _Objects_Get_no_protection()

This functions supports only local objects.  Thus, drop the location
parameter which was unused by all callers.

Remove superfluous includes from Classic Region implementation.
This commit is contained in:
Sebastian Huber
2016-04-12 07:36:18 +02:00
parent 0158a60cdc
commit 572cb62429
14 changed files with 194 additions and 328 deletions
+2 -7
View File
@@ -76,13 +76,8 @@ RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free(
RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Get( pthread_key_t key )
{
Objects_Locations location;
return (POSIX_Keys_Control *) _Objects_Get_no_protection(
&_POSIX_Keys_Information,
(Objects_Id) key,
&location
);
return (POSIX_Keys_Control *)
_Objects_Get_no_protection( &_POSIX_Keys_Information, (Objects_Id) key );
}
RTEMS_INLINE_ROUTINE void _POSIX_Keys_Key_value_acquire(
+2 -14
View File
@@ -67,23 +67,11 @@ RTEMS_INLINE_ROUTINE void _Region_Free (
_Objects_Free( &_Region_Information, &the_region->Object );
}
/**
* @brief Region_Get
*
* This function maps region IDs to region control blocks.
* If ID corresponds to a local region, then it returns
* the_region control pointer which maps to ID and location
* is set to OBJECTS_LOCAL. Otherwise, location is set
* to OBJECTS_ERROR and the_region is undefined.
*/
RTEMS_INLINE_ROUTINE Region_Control *_Region_Get (
Objects_Id id,
Objects_Locations *location
)
RTEMS_INLINE_ROUTINE Region_Control *_Region_Get( Objects_Id id )
{
_Assert( _RTEMS_Allocator_is_owner() );
return (Region_Control *)
_Objects_Get_no_protection( &_Region_Information, id, location );
_Objects_Get_no_protection( &_Region_Information, id );
}
/**
+14 -31
View File
@@ -18,50 +18,33 @@
#include "config.h"
#endif
#include <rtems/system.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/options.h>
#include <rtems/rtems/regionimpl.h>
#include <rtems/score/thread.h>
#include <rtems/score/apimutex.h>
rtems_status_code rtems_region_delete(
rtems_id id
)
{
Objects_Locations location;
rtems_status_code return_status;
Region_Control *the_region;
rtems_status_code status;
Region_Control *the_region;
_Objects_Allocator_lock();
_RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
the_region = _Region_Get( id );
case OBJECTS_LOCAL:
if ( the_region->number_of_used_blocks != 0 )
return_status = RTEMS_RESOURCE_IN_USE;
else {
_Objects_Close( &_Region_Information, &the_region->Object );
_Region_Free( the_region );
return_status = RTEMS_SUCCESSFUL;
}
break;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: /* this error cannot be returned */
#endif
case OBJECTS_ERROR:
default:
return_status = RTEMS_INVALID_ID;
break;
if ( the_region != NULL ) {
if ( the_region->number_of_used_blocks != 0 ) {
status = RTEMS_RESOURCE_IN_USE;
} else {
_Objects_Close( &_Region_Information, &the_region->Object );
_Region_Free( the_region );
status = RTEMS_SUCCESSFUL;
}
} else {
status = RTEMS_INVALID_ID;
}
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return return_status;
return status;
}
+24 -41
View File
@@ -18,13 +18,7 @@
#include "config.h"
#endif
#include <rtems/system.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/options.h>
#include <rtems/rtems/regionimpl.h>
#include <rtems/score/thread.h>
#include <rtems/score/apimutex.h>
rtems_status_code rtems_region_extend(
rtems_id id,
@@ -32,48 +26,37 @@ rtems_status_code rtems_region_extend(
uintptr_t length
)
{
uintptr_t amount_extended;
Objects_Locations location;
rtems_status_code return_status;
Region_Control *the_region;
rtems_status_code status;
Region_Control *the_region;
uintptr_t amount_extended;
if ( !starting_address )
if ( starting_address == NULL ) {
return RTEMS_INVALID_ADDRESS;
}
_RTEMS_Lock_allocator(); /* to prevent deletion */
_RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
the_region = _Region_Get( id );
case OBJECTS_LOCAL:
if ( the_region != NULL ) {
amount_extended = _Heap_Extend(
&the_region->Memory,
starting_address,
length,
0
);
amount_extended = _Heap_Extend(
&the_region->Memory,
starting_address,
length,
0
);
if ( amount_extended > 0 ) {
the_region->length += amount_extended;
the_region->maximum_segment_size += amount_extended;
return_status = RTEMS_SUCCESSFUL;
} else {
return_status = RTEMS_INVALID_ADDRESS;
}
break;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: /* this error cannot be returned */
#endif
case OBJECTS_ERROR:
default:
return_status = RTEMS_INVALID_ID;
break;
if ( amount_extended > 0 ) {
the_region->length += amount_extended;
the_region->maximum_segment_size += amount_extended;
status = RTEMS_SUCCESSFUL;
} else {
status = RTEMS_INVALID_ADDRESS;
}
} else {
status = RTEMS_INVALID_ID;
}
_RTEMS_Unlock_allocator();
return return_status;
return status;
}
+15 -33
View File
@@ -18,52 +18,34 @@
#include "config.h"
#endif
#include <rtems/system.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/options.h>
#include <rtems/rtems/regionimpl.h>
#include <rtems/score/apimutex.h>
#include <rtems/score/thread.h>
#include <string.h>
rtems_status_code rtems_region_get_free_information(
rtems_id id,
Heap_Information_block *the_info
)
{
Objects_Locations location;
rtems_status_code return_status;
Region_Control *the_region;
rtems_status_code status;
Region_Control *the_region;
if ( !the_info )
if ( the_info == NULL ) {
return RTEMS_INVALID_ADDRESS;
}
_RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
the_region = _Region_Get( id );
case OBJECTS_LOCAL:
the_info->Used.number = 0;
the_info->Used.total = 0;
the_info->Used.largest = 0;
_Heap_Get_free_information( &the_region->Memory, &the_info->Free );
return_status = RTEMS_SUCCESSFUL;
break;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: /* this error cannot be returned */
#endif
case OBJECTS_ERROR:
default:
return_status = RTEMS_INVALID_ID;
break;
}
if ( the_region != NULL ) {
memset( &the_info->Used, 0, sizeof( the_info->Used ) );
_Heap_Get_free_information( &the_region->Memory, &the_info->Free );
status = RTEMS_SUCCESSFUL;
} else {
status = RTEMS_INVALID_ID;
}
_RTEMS_Unlock_allocator();
return return_status;
return status;
}
+12 -27
View File
@@ -18,46 +18,31 @@
#include "config.h"
#endif
#include <rtems/system.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/options.h>
#include <rtems/rtems/regionimpl.h>
#include <rtems/score/apimutex.h>
#include <rtems/score/thread.h>
rtems_status_code rtems_region_get_information(
rtems_id id,
Heap_Information_block *the_info
)
{
Objects_Locations location;
rtems_status_code return_status;
Region_Control *the_region;
rtems_status_code status;
Region_Control *the_region;
if ( !the_info )
if ( the_info == NULL ) {
return RTEMS_INVALID_ADDRESS;
}
_RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
the_region = _Region_Get( id );
case OBJECTS_LOCAL:
_Heap_Get_information( &the_region->Memory, the_info );
return_status = RTEMS_SUCCESSFUL;
break;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: /* this error cannot be returned */
#endif
case OBJECTS_ERROR:
default:
return_status = RTEMS_INVALID_ID;
break;
}
if ( the_region != NULL ) {
_Heap_Get_information( &the_region->Memory, the_info );
status = RTEMS_SUCCESSFUL;
} else {
status = RTEMS_INVALID_ID;
}
_RTEMS_Unlock_allocator();
return return_status;
return status;
}
+48 -55
View File
@@ -20,7 +20,6 @@
#include <rtems/rtems/regionimpl.h>
#include <rtems/rtems/optionsimpl.h>
#include <rtems/score/apimutex.h>
#include <rtems/score/threadqimpl.h>
#include <rtems/score/statesimpl.h>
@@ -32,79 +31,73 @@ rtems_status_code rtems_region_get_segment(
void **segment
)
{
Thread_Control *executing;
Objects_Locations location;
rtems_status_code return_status;
Region_Control *the_region;
void *the_segment;
rtems_status_code status;
Region_Control *the_region;
if ( !segment )
if ( segment == NULL ) {
return RTEMS_INVALID_ADDRESS;
}
*segment = NULL;
if ( size == 0 )
if ( size == 0 ) {
return RTEMS_INVALID_SIZE;
}
_RTEMS_Lock_allocator();
executing = _Thread_Get_executing();
the_region = _Region_Get( id, &location );
switch ( location ) {
the_region = _Region_Get( id );
case OBJECTS_LOCAL:
if ( size > the_region->maximum_segment_size )
return_status = RTEMS_INVALID_SIZE;
if ( the_region != NULL ) {
if ( size > the_region->maximum_segment_size ) {
status = RTEMS_INVALID_SIZE;
} else {
void *the_segment;
else {
the_segment = _Region_Allocate_segment( the_region, size );
the_segment = _Region_Allocate_segment( the_region, size );
if ( the_segment ) {
the_region->number_of_used_blocks += 1;
*segment = the_segment;
return_status = RTEMS_SUCCESSFUL;
} else if ( _Options_Is_no_wait( option_set ) ) {
return_status = RTEMS_UNSATISFIED;
} else {
/*
* Switch from using the memory allocation mutex to using a
* dispatching disabled critical section. We have to do this
* because this thread is going to block.
*/
/* FIXME: Lock order reversal */
_Thread_Disable_dispatch();
_RTEMS_Unlock_allocator();
if ( the_segment != NULL ) {
the_region->number_of_used_blocks += 1;
*segment = the_segment;
status = RTEMS_SUCCESSFUL;
} else if ( _Options_Is_no_wait( option_set ) ) {
status = RTEMS_UNSATISFIED;
} else {
Per_CPU_Control *cpu_self;
Thread_Control *executing;
executing->Wait.count = size;
executing->Wait.return_argument = segment;
/*
* Switch from using the memory allocation mutex to using a
* dispatching disabled critical section. We have to do this
* because this thread is going to block.
*/
/* FIXME: This is a home grown condition variable */
cpu_self = _Thread_Dispatch_disable();
_RTEMS_Unlock_allocator();
_Thread_queue_Enqueue(
&the_region->Wait_queue,
the_region->wait_operations,
executing,
STATES_WAITING_FOR_SEGMENT,
timeout,
RTEMS_TIMEOUT
);
executing = _Per_CPU_Get_executing( cpu_self );
_Objects_Put( &the_region->Object );
executing->Wait.count = size;
executing->Wait.return_argument = segment;
return (rtems_status_code) executing->Wait.return_code;
}
}
break;
_Thread_queue_Enqueue(
&the_region->Wait_queue,
the_region->wait_operations,
executing,
STATES_WAITING_FOR_SEGMENT,
timeout,
RTEMS_TIMEOUT
);
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: /* this error cannot be returned */
#endif
_Thread_Dispatch_enable( cpu_self );
case OBJECTS_ERROR:
default:
return_status = RTEMS_INVALID_ID;
break;
return (rtems_status_code) executing->Wait.return_code;
}
}
} else {
status = RTEMS_INVALID_ID;
}
_RTEMS_Unlock_allocator();
return return_status;
return status;
}
+16 -25
View File
@@ -18,12 +18,7 @@
#include "config.h"
#endif
#include <rtems/system.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/options.h>
#include <rtems/rtems/regionimpl.h>
#include <rtems/score/apimutex.h>
rtems_status_code rtems_region_get_segment_size(
rtems_id id,
@@ -31,35 +26,31 @@ rtems_status_code rtems_region_get_segment_size(
uintptr_t *size
)
{
Objects_Locations location;
rtems_status_code return_status = RTEMS_SUCCESSFUL;
Region_Control *the_region;
rtems_status_code status;
Region_Control *the_region;
if ( !segment )
if ( segment == NULL ) {
return RTEMS_INVALID_ADDRESS;
}
if ( !size )
if ( size == NULL ) {
return RTEMS_INVALID_ADDRESS;
}
_RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
the_region = _Region_Get( id );
case OBJECTS_LOCAL:
if ( !_Heap_Size_of_alloc_area( &the_region->Memory, segment, size ) )
return_status = RTEMS_INVALID_ADDRESS;
break;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: /* this error cannot be returned */
#endif
case OBJECTS_ERROR:
return_status = RTEMS_INVALID_ID;
break;
if ( the_region != NULL ) {
if ( _Heap_Size_of_alloc_area( &the_region->Memory, segment, size ) ) {
status = RTEMS_SUCCESSFUL;
} else {
status = RTEMS_INVALID_ADDRESS;
}
} else {
status = RTEMS_INVALID_ID;
}
_RTEMS_Unlock_allocator();
return return_status;
return status;
}
+7 -5
View File
@@ -19,15 +19,16 @@
#endif
#include <rtems/rtems/regionimpl.h>
#include <rtems/score/apimutex.h>
#include <rtems/score/threadqimpl.h>
void _Region_Process_queue(
Region_Control *the_region
)
{
Thread_Control *the_thread;
void *the_segment;
Per_CPU_Control *cpu_self;
Thread_Control *the_thread;
void *the_segment;
/*
* Switch from using the memory allocation mutex to using a
* dispatching disabled critical section. We have to do this
@@ -38,7 +39,7 @@ void _Region_Process_queue(
* since we do not want to open a window where a context
* switch could occur.
*/
_Thread_Disable_dispatch();
cpu_self = _Thread_Dispatch_disable();
_RTEMS_Unlock_allocator();
/*
@@ -67,5 +68,6 @@ void _Region_Process_queue(
_Thread_queue_Extract( the_thread );
the_thread->Wait.return_code = RTEMS_SUCCESSFUL;
}
_Thread_Enable_dispatch();
_Thread_Dispatch_enable( cpu_self );
}
+29 -42
View File
@@ -18,13 +18,7 @@
#include "config.h"
#endif
#include <rtems/system.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/options.h>
#include <rtems/rtems/regionimpl.h>
#include <rtems/score/thread.h>
#include <rtems/score/apimutex.h>
rtems_status_code rtems_region_resize_segment(
rtems_id id,
@@ -33,55 +27,48 @@ rtems_status_code rtems_region_resize_segment(
uintptr_t *old_size
)
{
uintptr_t avail_size;
Objects_Locations location;
uintptr_t osize;
rtems_status_code return_status;
Heap_Resize_status status;
Region_Control *the_region;
uintptr_t avail_size;
uintptr_t osize;
rtems_status_code status;
Heap_Resize_status resize_status;
Region_Control *the_region;
if ( !old_size )
if ( old_size == NULL ) {
return RTEMS_INVALID_ADDRESS;
}
_RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
the_region = _Region_Get( id );
case OBJECTS_LOCAL:
status = _Heap_Resize_block(
&the_region->Memory,
segment,
(uint32_t) size,
&osize,
&avail_size
);
*old_size = (uint32_t) osize;
if ( the_region != NULL ) {
resize_status = _Heap_Resize_block(
&the_region->Memory,
segment,
(uint32_t) size,
&osize,
&avail_size
);
*old_size = (uint32_t) osize;
if ( status == HEAP_RESIZE_SUCCESSFUL )
/* unlocks allocator */
_Region_Process_queue( the_region );
else
_RTEMS_Unlock_allocator();
switch ( resize_status ) {
case HEAP_RESIZE_SUCCESSFUL:
/* Unlocks allocator */
_Region_Process_queue( the_region );
return RTEMS_SUCCESSFUL;
if (status == HEAP_RESIZE_SUCCESSFUL)
return RTEMS_SUCCESSFUL;
if (status == HEAP_RESIZE_UNSATISFIED)
return RTEMS_UNSATISFIED;
return RTEMS_INVALID_ADDRESS;
case HEAP_RESIZE_UNSATISFIED:
status = RTEMS_UNSATISFIED;
break;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: /* this error cannot be returned */
#endif
case OBJECTS_ERROR:
default:
return_status = RTEMS_INVALID_ID;
status = RTEMS_INVALID_ADDRESS;
break;
}
} else {
status = RTEMS_INVALID_ID;
}
_RTEMS_Unlock_allocator();
return return_status;
return status;
}
+16 -35
View File
@@ -18,53 +18,34 @@
#include "config.h"
#endif
#include <rtems/system.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/rtems/options.h>
#include <rtems/rtems/regionimpl.h>
#include <rtems/score/thread.h>
#include <rtems/score/apimutex.h>
rtems_status_code rtems_region_return_segment(
rtems_id id,
void *segment
)
{
Objects_Locations location;
rtems_status_code return_status;
int status;
Region_Control *the_region;
rtems_status_code status;
Region_Control *the_region;
_RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
the_region = _Region_Get( id );
case OBJECTS_LOCAL:
status = _Region_Free_segment( the_region, segment );
if ( the_region != NULL ) {
if ( _Region_Free_segment( the_region, segment ) ) {
the_region->number_of_used_blocks -= 1;
if ( !status )
return_status = RTEMS_INVALID_ADDRESS;
else {
the_region->number_of_used_blocks -= 1;
_Region_Process_queue(the_region); /* unlocks allocator */
return RTEMS_SUCCESSFUL;
}
break;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE: /* this error cannot be returned */
#endif
case OBJECTS_ERROR:
default:
return_status = RTEMS_INVALID_ID;
break;
}
/* Unlocks allocator */
_Region_Process_queue( the_region );
return RTEMS_SUCCESSFUL;
} else {
status = RTEMS_INVALID_ADDRESS;
}
} else {
status = RTEMS_INVALID_ID;
}
_RTEMS_Unlock_allocator();
return return_status;
return status;
}
@@ -614,7 +614,6 @@ Objects_Control *_Objects_Get_local(
*
* @param[in] information points to an object class information block.
* @param[in] id is the Id of the object whose name we are locating.
* @param[in] location will contain an indication of success or failure.
*
* @retval This method returns one of the values from the
* @ref Objects_Name_or_id_lookup_errors enumeration to indicate
@@ -627,9 +626,8 @@ Objects_Control *_Objects_Get_local(
* objects.
*/
Objects_Control *_Objects_Get_no_protection(
Objects_Information *information,
Objects_Id id,
Objects_Locations *location
const Objects_Information *information,
Objects_Id id
);
/**
+5 -4
View File
@@ -28,7 +28,7 @@ _Objects_Get_next(
Objects_Id *next_id_p
)
{
Objects_Control *object;
Objects_Control *the_object;
Objects_Id next_id;
if ( !information )
@@ -58,12 +58,13 @@ _Objects_Get_next(
}
/* try to grab one */
object = _Objects_Get_no_protection(information, next_id, location_p);
the_object = _Objects_Get_no_protection( information, next_id );
next_id++;
} while (*location_p != OBJECTS_LOCAL);
} while ( the_object == NULL );
*location_p = OBJECTS_LOCAL;
*next_id_p = next_id;
return object;
return the_object;
}
+2 -5
View File
@@ -21,9 +21,8 @@
#include <rtems/score/objectimpl.h>
Objects_Control *_Objects_Get_no_protection(
Objects_Information *information,
Objects_Id id,
Objects_Locations *location
const Objects_Information *information,
Objects_Id id
)
{
Objects_Control *the_object;
@@ -37,7 +36,6 @@ Objects_Control *_Objects_Get_no_protection(
if ( information->maximum >= index ) {
if ( (the_object = information->local_table[ index ]) != NULL ) {
*location = OBJECTS_LOCAL;
return the_object;
}
}
@@ -46,6 +44,5 @@ Objects_Control *_Objects_Get_no_protection(
* This isn't supported or required yet for Global objects so
* if it isn't local, we don't find it.
*/
*location = OBJECTS_ERROR;
return NULL;
}