summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems/src/regiongetsegment.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-08 06:56:46 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-12 07:36:19 +0200
commit1142f5593a5b6ab65d47bafb749e0709c7d2daa2 (patch)
tree44d5b886a880307bd6f38550a7275071f38965a7 /cpukit/rtems/src/regiongetsegment.c
parentscore: Simplify _Objects_Get_no_protection() (diff)
downloadrtems-1142f5593a5b6ab65d47bafb749e0709c7d2daa2.tar.bz2
rtems: Add and use _Region_Get_and_lock()
Get region and lock allocator in _Region_Get_and_lock() in case the region exists and unlock it in _Region_Unlock().
Diffstat (limited to 'cpukit/rtems/src/regiongetsegment.c')
-rw-r--r--cpukit/rtems/src/regiongetsegment.c96
1 files changed, 47 insertions, 49 deletions
diff --git a/cpukit/rtems/src/regiongetsegment.c b/cpukit/rtems/src/regiongetsegment.c
index 5a98e85ba4..ecc6378383 100644
--- a/cpukit/rtems/src/regiongetsegment.c
+++ b/cpukit/rtems/src/regiongetsegment.c
@@ -44,60 +44,58 @@ rtems_status_code rtems_region_get_segment(
return RTEMS_INVALID_SIZE;
}
- _RTEMS_Lock_allocator();
+ the_region = _Region_Get_and_lock( id );
- the_region = _Region_Get( id );
+ if ( the_region == NULL ) {
+ return RTEMS_INVALID_ID;
+ }
+
+ if ( size > the_region->maximum_segment_size ) {
+ status = RTEMS_INVALID_SIZE;
+ } else {
+ void *the_segment;
- if ( the_region != NULL ) {
- if ( size > the_region->maximum_segment_size ) {
- status = RTEMS_INVALID_SIZE;
+ 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 {
- 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;
- }
+ 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();
+ _Region_Unlock( the_region );
+
+ 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();
+ _Region_Unlock( the_region );
return status;
}