summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorGlenn Humphrey <glenn.humphrey@oarcorp.com>2007-11-27 17:38:11 +0000
committerGlenn Humphrey <glenn.humphrey@oarcorp.com>2007-11-27 17:38:11 +0000
commit5700b804e2443135a07c6ff5f65a024e7be412fd (patch)
tree8177dd1b95bd7698eac495c8403c6bf7828e2cf3 /cpukit
parent2007-11-27 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-5700b804e2443135a07c6ff5f65a024e7be412fd.tar.bz2
2007-11-27 Glenn Humphrey <glenn.humphrey@OARcorp.com>
* rtems/src/regioncreate.c, rtems/src/regiondelete.c, rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c, rtems/src/regionreturnsegment.c: Restructed to move the OBJECTS_LOCAL case to the top of the switch statement, have a single exit with one call to _RTEMS_Unlock_allocator and eliminate the fall-through return of RTEMS_INTERNAL_ERROR. These changes produced simplier assembly code and allowed for complete test coverage.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/ChangeLog12
-rw-r--r--cpukit/rtems/src/regioncreate.c85
-rw-r--r--cpukit/rtems/src/regiondelete.c47
-rw-r--r--cpukit/rtems/src/regionextend.c76
-rw-r--r--cpukit/rtems/src/regiongetfreeinfo.c43
-rw-r--r--cpukit/rtems/src/regiongetinfo.c43
-rw-r--r--cpukit/rtems/src/regiongetsegment.c100
-rw-r--r--cpukit/rtems/src/regiongetsegmentsize.c44
-rw-r--r--cpukit/rtems/src/regionresizesegment.c71
-rw-r--r--cpukit/rtems/src/regionreturnsegment.c65
10 files changed, 310 insertions, 276 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 146344808b..3ffcf7b25e 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,15 @@
+2007-11-27 Glenn Humphrey <glenn.humphrey@OARcorp.com>
+
+ * rtems/src/regioncreate.c, rtems/src/regiondelete.c,
+ rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c,
+ rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c,
+ rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c,
+ rtems/src/regionreturnsegment.c: Restructed to move the OBJECTS_LOCAL
+ case to the top of the switch statement, have a single exit with one
+ call to _RTEMS_Unlock_allocator and eliminate the fall-through return
+ of RTEMS_INTERNAL_ERROR. These changes produced simplier assembly
+ code and allowed for complete test coverage.
+
2007-11-27 Joel Sherrill <joel.sherrill@oarcorp.com>
* sapi/include/confdefs.h: Add CONFIGURE_APPLICATION_EXTRA_DRIVERS.
diff --git a/cpukit/rtems/src/regioncreate.c b/cpukit/rtems/src/regioncreate.c
index 1f4b8ae94b..ec305b71a3 100644
--- a/cpukit/rtems/src/regioncreate.c
+++ b/cpukit/rtems/src/regioncreate.c
@@ -56,7 +56,8 @@ rtems_status_code rtems_region_create(
Objects_Id *id
)
{
- Region_Control *the_region;
+ rtems_status_code return_status;
+ Region_Control *the_region;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -72,43 +73,49 @@ rtems_status_code rtems_region_create(
_RTEMS_Lock_allocator(); /* to prevent deletion */
- the_region = _Region_Allocate();
-
- if ( !the_region ) {
- _RTEMS_Unlock_allocator();
- return RTEMS_TOO_MANY;
- }
-
- the_region->maximum_segment_size =
- _Heap_Initialize(&the_region->Memory, starting_address, length, page_size);
-
- if ( !the_region->maximum_segment_size ) {
- _Region_Free( the_region );
- _RTEMS_Unlock_allocator();
- return RTEMS_INVALID_SIZE;
- }
-
- the_region->starting_address = starting_address;
- the_region->length = length;
- the_region->page_size = page_size;
- the_region->attribute_set = attribute_set;
- the_region->number_of_used_blocks = 0;
-
- _Thread_queue_Initialize(
- &the_region->Wait_queue,
- _Attributes_Is_priority( attribute_set ) ?
- THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
- STATES_WAITING_FOR_SEGMENT,
- RTEMS_TIMEOUT
- );
-
- _Objects_Open(
- &_Region_Information,
- &the_region->Object,
- (Objects_Name) name
- );
-
- *id = the_region->Object.id;
+ the_region = _Region_Allocate();
+
+ if ( !the_region )
+ return_status = RTEMS_TOO_MANY;
+
+ else {
+
+ the_region->maximum_segment_size = _Heap_Initialize(
+ &the_region->Memory, starting_address, length, page_size
+ );
+
+ if ( !the_region->maximum_segment_size ) {
+ _Region_Free( the_region );
+ return_status = RTEMS_INVALID_SIZE;
+ }
+
+ else {
+
+ the_region->starting_address = starting_address;
+ the_region->length = length;
+ the_region->page_size = page_size;
+ the_region->attribute_set = attribute_set;
+ the_region->number_of_used_blocks = 0;
+
+ _Thread_queue_Initialize(
+ &the_region->Wait_queue,
+ _Attributes_Is_priority( attribute_set ) ?
+ THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
+ STATES_WAITING_FOR_SEGMENT,
+ RTEMS_TIMEOUT
+ );
+
+ _Objects_Open(
+ &_Region_Information,
+ &the_region->Object,
+ (Objects_Name) name
+ );
+
+ *id = the_region->Object.id;
+ return_status = RTEMS_SUCCESSFUL;
+ }
+ }
+
_RTEMS_Unlock_allocator();
- return RTEMS_SUCCESSFUL;
+ return return_status;
}
diff --git a/cpukit/rtems/src/regiondelete.c b/cpukit/rtems/src/regiondelete.c
index 6788282750..2b96aa9720 100644
--- a/cpukit/rtems/src/regiondelete.c
+++ b/cpukit/rtems/src/regiondelete.c
@@ -46,33 +46,36 @@ rtems_status_code rtems_region_delete(
Objects_Id id
)
{
- register Region_Control *the_region;
Objects_Locations location;
+ rtems_status_code return_status = RTEMS_INTERNAL_ERROR;
+ register Region_Control *the_region;
_RTEMS_Lock_allocator();
- the_region = _Region_Get( id, &location );
- switch ( location ) {
+
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+ _Region_Debug_Walk( the_region, 5 );
+ 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 */
- _RTEMS_Unlock_allocator();
- return RTEMS_INTERNAL_ERROR;
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
#endif
- case OBJECTS_ERROR:
- _RTEMS_Unlock_allocator();
- return RTEMS_INVALID_ID;
-
- case OBJECTS_LOCAL:
- _Region_Debug_Walk( the_region, 5 );
- if ( the_region->number_of_used_blocks == 0 ) {
- _Objects_Close( &_Region_Information, &the_region->Object );
- _Region_Free( the_region );
- _RTEMS_Unlock_allocator();
- return RTEMS_SUCCESSFUL;
- }
- _RTEMS_Unlock_allocator();
- return RTEMS_RESOURCE_IN_USE;
- }
+ case OBJECTS_ERROR:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
- return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
+ _RTEMS_Unlock_allocator();
+ return return_status;
}
diff --git a/cpukit/rtems/src/regionextend.c b/cpukit/rtems/src/regionextend.c
index 66e9fea936..d8ad00b55c 100644
--- a/cpukit/rtems/src/regionextend.c
+++ b/cpukit/rtems/src/regionextend.c
@@ -49,54 +49,54 @@ rtems_status_code rtems_region_extend(
uint32_t length
)
{
- Region_Control *the_region;
- Objects_Locations location;
uint32_t amount_extended;
Heap_Extend_status heap_status;
- rtems_status_code status;
+ Objects_Locations location;
+ rtems_status_code return_status = RTEMS_INTERNAL_ERROR;
+ Region_Control *the_region;
if ( !starting_address )
return RTEMS_INVALID_ADDRESS;
- status = RTEMS_SUCCESSFUL;
-
_RTEMS_Lock_allocator(); /* to prevent deletion */
- 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;
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
+
+ heap_status = _Heap_Extend(
+ &the_region->Memory,
+ starting_address,
+ length,
+ &amount_extended
+ );
- case OBJECTS_LOCAL:
+ switch ( heap_status ) {
+ case HEAP_EXTEND_SUCCESSFUL:
+ the_region->length += amount_extended;
+ the_region->maximum_segment_size += amount_extended;
+ return_status = RTEMS_SUCCESSFUL;
+ break;
+ case HEAP_EXTEND_ERROR:
+ return_status = RTEMS_INVALID_ADDRESS;
+ break;
+ case HEAP_EXTEND_NOT_IMPLEMENTED:
+ return_status = RTEMS_NOT_IMPLEMENTED;
+ break;
+ }
+ break;
- heap_status = _Heap_Extend(
- &the_region->Memory,
- starting_address,
- length,
- &amount_extended
- );
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
- switch ( heap_status ) {
- case HEAP_EXTEND_SUCCESSFUL:
- the_region->length += amount_extended;
- the_region->maximum_segment_size += amount_extended;
- break;
- case HEAP_EXTEND_ERROR:
- status = RTEMS_INVALID_ADDRESS;
- break;
- case HEAP_EXTEND_NOT_IMPLEMENTED:
- status = RTEMS_NOT_IMPLEMENTED;
- break;
- }
- _RTEMS_Unlock_allocator();
- return( status );
- }
+ case OBJECTS_ERROR:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
- return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
+ _RTEMS_Unlock_allocator();
+ return return_status;
}
diff --git a/cpukit/rtems/src/regiongetfreeinfo.c b/cpukit/rtems/src/regiongetfreeinfo.c
index 3ad06374fb..2346b5e7c4 100644
--- a/cpukit/rtems/src/regiongetfreeinfo.c
+++ b/cpukit/rtems/src/regiongetfreeinfo.c
@@ -49,36 +49,39 @@ rtems_status_code rtems_region_get_free_information(
Heap_Information_block *the_info
)
{
- register Region_Control *the_region;
Objects_Locations location;
+ rtems_status_code return_status = RTEMS_INTERNAL_ERROR;
+ register Region_Control *the_region;
if ( !the_info )
return RTEMS_INVALID_ADDRESS;
_RTEMS_Lock_allocator();
- 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;
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
- case OBJECTS_LOCAL:
+ case OBJECTS_LOCAL:
- the_info->Used.number = 0;
- the_info->Used.total = 0;
- the_info->Used.largest = 0;
+ 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 );
+ _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 */
+ break;
+#endif
- _RTEMS_Unlock_allocator();
- return RTEMS_SUCCESSFUL;
- }
+ case OBJECTS_ERROR:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
- return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
+ _RTEMS_Unlock_allocator();
+ return return_status;
}
diff --git a/cpukit/rtems/src/regiongetinfo.c b/cpukit/rtems/src/regiongetinfo.c
index 9843338b0a..2fad55dcff 100644
--- a/cpukit/rtems/src/regiongetinfo.c
+++ b/cpukit/rtems/src/regiongetinfo.c
@@ -47,35 +47,36 @@ rtems_status_code rtems_region_get_information(
Heap_Information_block *the_info
)
{
- register Region_Control *the_region;
Objects_Locations location;
+ rtems_status_code return_status = RTEMS_INTERNAL_ERROR;
+ register Region_Control *the_region;
if ( !the_info )
return RTEMS_INVALID_ADDRESS;
_RTEMS_Lock_allocator();
- 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;
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
- case OBJECTS_LOCAL:
+ case OBJECTS_LOCAL:
+ if ( _Heap_Get_information( &the_region->Memory, the_info ) !=
+ HEAP_GET_INFORMATION_SUCCESSFUL )
+ return_status = RTEMS_INVALID_ADDRESS;
+ else
+ return_status = RTEMS_SUCCESSFUL;
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
- if ( _Heap_Get_information( &the_region->Memory, the_info ) ==
- HEAP_GET_INFORMATION_SUCCESSFUL ) {
- _RTEMS_Unlock_allocator();
- return RTEMS_SUCCESSFUL;
- }
- _RTEMS_Unlock_allocator();
- return RTEMS_INVALID_ADDRESS;
- }
+ case OBJECTS_ERROR:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
- return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
+ _RTEMS_Unlock_allocator();
+ return return_status;
}
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;
}
diff --git a/cpukit/rtems/src/regiongetsegmentsize.c b/cpukit/rtems/src/regiongetsegmentsize.c
index c89efd0d36..7d70b6188b 100644
--- a/cpukit/rtems/src/regiongetsegmentsize.c
+++ b/cpukit/rtems/src/regiongetsegmentsize.c
@@ -23,7 +23,6 @@
#include <rtems/rtems/options.h>
#include <rtems/rtems/region.h>
#include <rtems/score/states.h>
-#include <rtems/score/thread.h>
#include <rtems/score/apimutex.h>
/*PAGE
@@ -49,9 +48,9 @@ rtems_status_code rtems_region_get_segment_size(
size_t *size
)
{
- register Region_Control *the_region;
Objects_Locations location;
- Thread_Control *executing;
+ rtems_status_code return_status = RTEMS_INTERNAL_ERROR;
+ register Region_Control *the_region;
if ( !segment )
return RTEMS_INVALID_ADDRESS;
@@ -60,28 +59,27 @@ rtems_status_code rtems_region_get_segment_size(
return RTEMS_INVALID_ADDRESS;
_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;
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
- case OBJECTS_LOCAL:
+ case OBJECTS_LOCAL:
+ if ( !_Heap_Size_of_user_area( &the_region->Memory, segment, size ) )
+ return_status = RTEMS_INVALID_ADDRESS;
+ else
+ return_status = RTEMS_SUCCESSFUL;
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
- if ( _Heap_Size_of_user_area( &the_region->Memory, segment, size ) ) {
- _RTEMS_Unlock_allocator();
- return RTEMS_SUCCESSFUL;
- }
- _RTEMS_Unlock_allocator();
- return RTEMS_INVALID_ADDRESS;
- }
+ case OBJECTS_ERROR:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
- return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
+ _RTEMS_Unlock_allocator();
+ return return_status;
}
diff --git a/cpukit/rtems/src/regionresizesegment.c b/cpukit/rtems/src/regionresizesegment.c
index ab74eb35a0..43cb302afd 100644
--- a/cpukit/rtems/src/regionresizesegment.c
+++ b/cpukit/rtems/src/regionresizesegment.c
@@ -50,54 +50,57 @@ rtems_status_code rtems_region_resize_segment(
size_t *old_size
)
{
- register Region_Control *the_region;
- Objects_Locations location;
- Heap_Resize_status status;
uint32_t avail_size;
+ Objects_Locations location;
uint32_t osize;
+ rtems_status_code return_status = RTEMS_INTERNAL_ERROR;
+ Heap_Resize_status status;
+ register Region_Control *the_region;
if ( !old_size )
return RTEMS_INVALID_ADDRESS;
_RTEMS_Lock_allocator();
- 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
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
+
+ case OBJECTS_LOCAL:
- case OBJECTS_ERROR:
- _RTEMS_Unlock_allocator();
- return RTEMS_INVALID_ID;
+ _Region_Debug_Walk( the_region, 7 );
- case OBJECTS_LOCAL:
+ status = _Heap_Resize_block(
+ &the_region->Memory,
+ segment,
+ (uint32_t) size,
+ &osize,
+ &avail_size
+ );
+ *old_size = (uint32_t) osize;
- _Region_Debug_Walk( the_region, 7 );
+ _Region_Debug_Walk( the_region, 8 );
- status = _Heap_Resize_block(
- &the_region->Memory,
- segment,
- (uint32_t) size,
- &osize,
- &avail_size
- );
- *old_size = (uint32_t) osize;
+ if ( status == HEAP_RESIZE_SUCCESSFUL && avail_size > 0 )
+ _Region_Process_queue( the_region ); /* unlocks allocator */
+ else
+ _RTEMS_Unlock_allocator();
- _Region_Debug_Walk( the_region, 8 );
+ return
+ (status == HEAP_RESIZE_SUCCESSFUL) ? RTEMS_SUCCESSFUL :
+ (status == HEAP_RESIZE_UNSATISFIED) ? RTEMS_UNSATISFIED :
+ RTEMS_INVALID_ADDRESS;
+ break;
- if( status == HEAP_RESIZE_SUCCESSFUL && avail_size > 0 )
- _Region_Process_queue( the_region ); /* unlocks allocator internally */
- else
- _RTEMS_Unlock_allocator();
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
- return
- (status == HEAP_RESIZE_SUCCESSFUL) ? RTEMS_SUCCESSFUL :
- (status == HEAP_RESIZE_UNSATISFIED) ? RTEMS_UNSATISFIED :
- RTEMS_INVALID_ADDRESS;
- }
+ case OBJECTS_ERROR:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
- return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
+ _RTEMS_Unlock_allocator();
+ return return_status;
}
diff --git a/cpukit/rtems/src/regionreturnsegment.c b/cpukit/rtems/src/regionreturnsegment.c
index 4c08b44d59..0da5f1ca79 100644
--- a/cpukit/rtems/src/regionreturnsegment.c
+++ b/cpukit/rtems/src/regionreturnsegment.c
@@ -54,55 +54,58 @@ rtems_status_code rtems_region_return_segment(
void *segment
)
{
- register Region_Control *the_region;
Objects_Locations location;
+ rtems_status_code return_status = RTEMS_INTERNAL_ERROR;
#ifdef RTEMS_REGION_FREE_SHRED_PATTERN
uint32_t size;
#endif
int status;
+ register Region_Control *the_region;
_RTEMS_Lock_allocator();
- 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;
+ the_region = _Region_Get( id, &location );
+ switch ( location ) {
- case OBJECTS_LOCAL:
+ case OBJECTS_LOCAL:
- _Region_Debug_Walk( the_region, 3 );
+ _Region_Debug_Walk( the_region, 3 );
#ifdef RTEMS_REGION_FREE_SHRED_PATTERN
- if ( _Heap_Size_of_user_area( &the_region->Memory, segment, &size ) ) {
- memset( segment, (RTEMS_REGION_FREE_SHRED_PATTERN & 0xFF), size );
- } else {
- _RTEMS_Unlock_allocator();
- return RTEMS_INVALID_ADDRESS;
- }
+ if ( !_Heap_Size_of_user_area( &the_region->Memory, segment, &size ) )
+ return_status = RTEMS_INVALID_ADDRESS;
+ else {
+ memset( segment, (RTEMS_REGION_FREE_SHRED_PATTERN & 0xFF), size );
#endif
+ status = _Region_Free_segment( the_region, segment );
- status = _Region_Free_segment( the_region, segment );
+ _Region_Debug_Walk( the_region, 4 );
- _Region_Debug_Walk( the_region, 4 );
+ if ( !status )
+ return_status = RTEMS_INVALID_ADDRESS;
- if ( !status ) {
- _RTEMS_Unlock_allocator();
- return RTEMS_INVALID_ADDRESS;
- }
+ else {
+ the_region->number_of_used_blocks -= 1;
- the_region->number_of_used_blocks -= 1;
+ _Region_Process_queue(the_region); /* unlocks allocator */
- _Region_Process_queue(the_region); /* unlocks allocator internally */
+ return RTEMS_SUCCESSFUL;
+ }
+#ifdef RTEMS_REGION_FREE_SHRED_PATTERN
+ }
+#endif
+ break;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ case OBJECTS_REMOTE: /* this error cannot be returned */
+ break;
+#endif
- return RTEMS_SUCCESSFUL;
- }
+ case OBJECTS_ERROR:
+ return_status = RTEMS_INVALID_ID;
+ break;
+ }
- return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
+ _RTEMS_Unlock_allocator();
+ return return_status;
}