diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-07 16:48:30 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-04-12 07:36:18 +0200 |
commit | 572cb6242969f96a5bf74dc107e3f845894b6b2b (patch) | |
tree | be87de631165d9314f36ad6d48e15b8ca8fb9d7b /cpukit/rtems/src/regiongetsegment.c | |
parent | rtems: Ensure lock ownership for _Region_Get() (diff) | |
download | rtems-572cb6242969f96a5bf74dc107e3f845894b6b2b.tar.bz2 |
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.
Diffstat (limited to 'cpukit/rtems/src/regiongetsegment.c')
-rw-r--r-- | cpukit/rtems/src/regiongetsegment.c | 121 |
1 files changed, 57 insertions, 64 deletions
diff --git a/cpukit/rtems/src/regiongetsegment.c b/cpukit/rtems/src/regiongetsegment.c index 0d1ac574dd..5a98e85ba4 100644 --- a/cpukit/rtems/src/regiongetsegment.c +++ b/cpukit/rtems/src/regiongetsegment.c @@ -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 ) { - - case OBJECTS_LOCAL: - if ( size > the_region->maximum_segment_size ) - return_status = RTEMS_INVALID_SIZE; - - else { - 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(); - - executing->Wait.count = size; - executing->Wait.return_argument = segment; - - _Thread_queue_Enqueue( - &the_region->Wait_queue, - the_region->wait_operations, - executing, - STATES_WAITING_FOR_SEGMENT, - timeout, - RTEMS_TIMEOUT - ); - - _Objects_Put( &the_region->Object ); - - return (rtems_status_code) executing->Wait.return_code; - } - } - break; - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: /* this error cannot be returned */ -#endif - - case OBJECTS_ERROR: - default: - return_status = RTEMS_INVALID_ID; - break; + the_region = _Region_Get( id ); + + if ( the_region != NULL ) { + if ( size > the_region->maximum_segment_size ) { + status = RTEMS_INVALID_SIZE; + } else { + void *the_segment; + + the_segment = _Region_Allocate_segment( the_region, size ); + + 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; + + /* + * 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(); + + executing = _Per_CPU_Get_executing( cpu_self ); + + executing->Wait.count = size; + executing->Wait.return_argument = segment; + + _Thread_queue_Enqueue( + &the_region->Wait_queue, + the_region->wait_operations, + executing, + STATES_WAITING_FOR_SEGMENT, + timeout, + RTEMS_TIMEOUT + ); + + _Thread_Dispatch_enable( cpu_self ); + + return (rtems_status_code) executing->Wait.return_code; + } } + } else { + status = RTEMS_INVALID_ID; + } _RTEMS_Unlock_allocator(); - - return return_status; + return status; } |