From edcf89b6f29b532360c2066446e4571286cbf705 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 27 Mar 2015 21:08:21 +0100 Subject: rtems: Atomically suspend/resume tasks --- cpukit/rtems/src/taskresume.c | 11 +++++------ cpukit/rtems/src/tasksuspend.c | 11 +++++------ cpukit/score/include/rtems/score/threadimpl.h | 15 --------------- testsuites/tmtests/tm26/task1.c | 2 +- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/cpukit/rtems/src/taskresume.c b/cpukit/rtems/src/taskresume.c index 86a22e195a..ed06a22e4a 100644 --- a/cpukit/rtems/src/taskresume.c +++ b/cpukit/rtems/src/taskresume.c @@ -27,18 +27,17 @@ rtems_status_code rtems_task_resume( { Thread_Control *the_thread; Objects_Locations location; + States_Control previous_state; the_thread = _Thread_Get( id, &location ); switch ( location ) { case OBJECTS_LOCAL: - if ( _States_Is_suspended( the_thread->current_state ) ) { - _Thread_Resume( the_thread ); - _Objects_Put( &the_thread->Object ); - return RTEMS_SUCCESSFUL; - } + previous_state = _Thread_Clear_state( the_thread, STATES_SUSPENDED ); _Objects_Put( &the_thread->Object ); - return RTEMS_INCORRECT_STATE; + + return _States_Is_suspended( previous_state ) ? + RTEMS_SUCCESSFUL : RTEMS_INCORRECT_STATE; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: diff --git a/cpukit/rtems/src/tasksuspend.c b/cpukit/rtems/src/tasksuspend.c index f8c43a73f1..ae7995a53c 100644 --- a/cpukit/rtems/src/tasksuspend.c +++ b/cpukit/rtems/src/tasksuspend.c @@ -27,18 +27,17 @@ rtems_status_code rtems_task_suspend( { Thread_Control *the_thread; Objects_Locations location; + States_Control previous_state; the_thread = _Thread_Get( id, &location ); switch ( location ) { case OBJECTS_LOCAL: - if ( !_States_Is_suspended( the_thread->current_state ) ) { - _Thread_Suspend( the_thread ); - _Objects_Put( &the_thread->Object ); - return RTEMS_SUCCESSFUL; - } + previous_state = _Thread_Set_state( the_thread, STATES_SUSPENDED ); _Objects_Put( &the_thread->Object ); - return RTEMS_ALREADY_SUSPENDED; + + return _States_Is_suspended( previous_state ) ? + RTEMS_ALREADY_SUSPENDED : RTEMS_SUCCESSFUL; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h index 65625b6011..0f37655e0c 100644 --- a/cpukit/score/include/rtems/score/threadimpl.h +++ b/cpukit/score/include/rtems/score/threadimpl.h @@ -355,21 +355,6 @@ void _Thread_Set_priority( Priority_Control new_priority ); -/** - * This routine updates the related suspend fields in the_thread - * control block to indicate the current nested level. - */ -#define _Thread_Suspend( _the_thread ) \ - _Thread_Set_state( _the_thread, STATES_SUSPENDED ) - -/** - * This routine updates the related suspend fields in the_thread - * control block to indicate the current nested level. A force - * parameter of true will force a resume and clear the suspend count. - */ -#define _Thread_Resume( _the_thread ) \ - _Thread_Clear_state( _the_thread, STATES_SUSPENDED ) - /** * @brief Maps thread Id to a TCB pointer. * diff --git a/testsuites/tmtests/tm26/task1.c b/testsuites/tmtests/tm26/task1.c index 5d74872ea9..6cec7dafbb 100644 --- a/testsuites/tmtests/tm26/task1.c +++ b/testsuites/tmtests/tm26/task1.c @@ -174,7 +174,7 @@ static void thread_resume( Thread_Control *thread ) _Thread_Disable_dispatch(); #endif - _Thread_Resume( thread ); + _Thread_Clear_state( thread, STATES_SUSPENDED ); #if defined( PREVENT_SMP_ASSERT_FAILURES ) _Thread_Unnest_dispatch(); -- cgit v1.2.3