diff options
Diffstat (limited to 'cpukit/rtems/src/regiongetsegment.c')
-rw-r--r-- | cpukit/rtems/src/regiongetsegment.c | 100 |
1 files changed, 52 insertions, 48 deletions
diff --git a/cpukit/rtems/src/regiongetsegment.c b/cpukit/rtems/src/regiongetsegment.c index 6340cd915e..c8b7d46233 100644 --- a/cpukit/rtems/src/regiongetsegment.c +++ b/cpukit/rtems/src/regiongetsegment.c @@ -53,9 +53,10 @@ rtems_status_code rtems_region_get_segment( void **segment ) { - register Region_Control *the_region; - Objects_Locations location; Thread_Control *executing; + Objects_Locations location; + rtems_status_code return_status = RTEMS_INTERNAL_ERROR; + register Region_Control *the_region; void *the_segment; if ( !segment ) @@ -67,64 +68,67 @@ rtems_status_code rtems_region_get_segment( return RTEMS_INVALID_SIZE; _RTEMS_Lock_allocator(); - executing = _Thread_Executing; - the_region = _Region_Get( id, &location ); - switch ( location ) { -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: /* this error cannot be returned */ - _RTEMS_Unlock_allocator(); - return RTEMS_INTERNAL_ERROR; -#endif - case OBJECTS_ERROR: - _RTEMS_Unlock_allocator(); - return RTEMS_INVALID_ID; + executing = _Thread_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 { + _Region_Debug_Walk( the_region, 1 ); - case OBJECTS_LOCAL: - if ( size > the_region->maximum_segment_size ) { - _RTEMS_Unlock_allocator(); - return RTEMS_INVALID_SIZE; - } + the_segment = _Region_Allocate_segment( the_region, size ); - _Region_Debug_Walk( the_region, 1 ); + _Region_Debug_Walk( the_region, 2 ); - 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; + } - _Region_Debug_Walk( the_region, 2 ); + else if ( _Options_Is_no_wait( option_set ) ) { + return_status = RTEMS_UNSATISFIED; + } - if ( the_segment ) { - the_region->number_of_used_blocks += 1; - _RTEMS_Unlock_allocator(); - *segment = the_segment; - return RTEMS_SUCCESSFUL; - } + 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. + */ + _Thread_Disable_dispatch(); + _RTEMS_Unlock_allocator(); - if ( _Options_Is_no_wait( option_set ) ) { - _RTEMS_Unlock_allocator(); - return RTEMS_UNSATISFIED; - } + executing->Wait.queue = &the_region->Wait_queue; + executing->Wait.id = id; + 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. - */ - _Thread_Disable_dispatch(); - _RTEMS_Unlock_allocator(); + _Thread_queue_Enter_critical_section( &the_region->Wait_queue ); - executing->Wait.queue = &the_region->Wait_queue; - executing->Wait.id = id; - executing->Wait.count = size; - executing->Wait.return_argument = segment; + _Thread_queue_Enqueue( &the_region->Wait_queue, timeout ); - _Thread_queue_Enter_critical_section( &the_region->Wait_queue ); + _Thread_Enable_dispatch(); - _Thread_queue_Enqueue( &the_region->Wait_queue, timeout ); + return (rtems_status_code) executing->Wait.return_code; + } + } + break; - _Thread_Enable_dispatch(); +#if defined(RTEMS_MULTIPROCESSING) + case OBJECTS_REMOTE: /* this error cannot be returned */ + break; +#endif - return (rtems_status_code) executing->Wait.return_code; - } + case OBJECTS_ERROR: + return_status = RTEMS_INVALID_ID; + break; + } - return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ + _RTEMS_Unlock_allocator(); + return return_status; } |