From 125f248231c173a038ed9fc00832e0b3d221ad43 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 16 Nov 2016 16:39:43 +0100 Subject: score: Add thread queue enqueue callout Replace the expected thread dispatch disable level with a thread queue enqueue callout. This enables the use of _Thread_Dispatch_direct() in the thread queue enqueue procedure. This avoids impossible exection paths, e.g. Per_CPU_Control::dispatch_necessary is always true. --- cpukit/rtems/include/rtems/rtems/regionimpl.h | 3 ++ cpukit/rtems/src/regiongetsegment.c | 46 +++++++++++++++------------ cpukit/rtems/src/taskdelete.c | 26 ++++++++------- 3 files changed, 44 insertions(+), 31 deletions(-) (limited to 'cpukit/rtems') diff --git a/cpukit/rtems/include/rtems/rtems/regionimpl.h b/cpukit/rtems/include/rtems/rtems/regionimpl.h index 1f31ad4adb..178b7ea32b 100644 --- a/cpukit/rtems/include/rtems/rtems/regionimpl.h +++ b/cpukit/rtems/include/rtems/rtems/regionimpl.h @@ -35,6 +35,9 @@ extern "C" { * @{ */ +#define REGION_OF_THREAD_QUEUE_QUEUE( queue ) \ + RTEMS_CONTAINER_OF( queue, Region_Control, Wait_queue.Queue ) + /** * The following defines the information control block used to * manage this class of objects. diff --git a/cpukit/rtems/src/regiongetsegment.c b/cpukit/rtems/src/regiongetsegment.c index ec0c52519b..dc17b21956 100644 --- a/cpukit/rtems/src/regiongetsegment.c +++ b/cpukit/rtems/src/regiongetsegment.c @@ -24,6 +24,18 @@ #include #include +static void _Region_Enqueue_callout( + Thread_queue_Queue *queue, + Thread_Control *the_thread, + Thread_queue_Context *queue_context +) +{ + Region_Control *the_region; + + the_region = REGION_OF_THREAD_QUEUE_QUEUE( queue ); + _Region_Unlock( the_region ); +} + rtems_status_code rtems_region_get_segment( rtems_id id, uintptr_t size, @@ -64,35 +76,29 @@ rtems_status_code rtems_region_get_segment( } 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(); - _Region_Unlock( the_region ); + Thread_queue_Context queue_context; + Thread_Control *executing; - executing = _Per_CPU_Get_executing( cpu_self ); + _Thread_queue_Context_initialize( &queue_context ); + _Thread_queue_Acquire( &the_region->Wait_queue, &queue_context ); + executing = _Thread_Executing; executing->Wait.count = size; executing->Wait.return_argument = segment; - _Thread_queue_Enqueue( - &the_region->Wait_queue, + /* FIXME: This is a home grown condition variable */ + _Thread_queue_Context_set_enqueue_callout( + &queue_context, + _Region_Enqueue_callout + ); + _Thread_queue_Context_set_relative_timeout( &queue_context, timeout ); + _Thread_queue_Enqueue_critical( + &the_region->Wait_queue.Queue, the_region->wait_operations, executing, STATES_WAITING_FOR_SEGMENT, - timeout, - WATCHDOG_RELATIVE, - 2 + &queue_context ); - - _Thread_Dispatch_enable( cpu_self ); - return _Status_Get_after_wait( executing ); } } diff --git a/cpukit/rtems/src/taskdelete.c b/cpukit/rtems/src/taskdelete.c index c3ddc77d0a..de57fb3ec0 100644 --- a/cpukit/rtems/src/taskdelete.c +++ b/cpukit/rtems/src/taskdelete.c @@ -25,12 +25,12 @@ rtems_status_code rtems_task_delete( rtems_id id ) { - Thread_Control *the_thread; - ISR_lock_Context lock_context; - Thread_Control *executing; - Per_CPU_Control *cpu_self; + Thread_Control *the_thread; + Thread_Close_context context; + Thread_Control *executing; - the_thread = _Thread_Get( id, &lock_context ); + _Thread_queue_Context_initialize( &context.Base ); + the_thread = _Thread_Get( id, &context.Base.Lock_context.Lock_context ); if ( the_thread == NULL ) { #if defined(RTEMS_MULTIPROCESSING) @@ -42,12 +42,16 @@ rtems_status_code rtems_task_delete( return RTEMS_INVALID_ID; } - cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); - _ISR_lock_ISR_enable( &lock_context ); - - executing = _Per_CPU_Get_executing( cpu_self ); + executing = _Thread_Executing; if ( the_thread == executing ) { + Per_CPU_Control *cpu_self; + + cpu_self = _Thread_Dispatch_disable_critical( + &context.Base.Lock_context.Lock_context + ); + _ISR_lock_ISR_enable( &context.Base.Lock_context.Lock_context ); + /* * The Classic tasks are neither detached nor joinable. In case of * self deletion, they are detached, otherwise joinable by default. @@ -57,10 +61,10 @@ rtems_status_code rtems_task_delete( THREAD_LIFE_TERMINATING | THREAD_LIFE_DETACHED, NULL ); + _Thread_Dispatch_enable( cpu_self ); } else { - _Thread_Close( the_thread, executing ); + _Thread_Close( the_thread, executing, &context ); } - _Thread_Dispatch_enable( cpu_self ); return RTEMS_SUCCESSFUL; } -- cgit v1.2.3