summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2015-03-27 21:08:21 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-04-08 11:48:15 +0200
commitedcf89b6f29b532360c2066446e4571286cbf705 (patch)
tree8f2a524a492df1b2f66a25fa8876296dbc26f049
parentscore: Return prev state in thread state set/clear (diff)
downloadrtems-edcf89b6f29b532360c2066446e4571286cbf705.tar.bz2
rtems: Atomically suspend/resume tasks
-rw-r--r--cpukit/rtems/src/taskresume.c11
-rw-r--r--cpukit/rtems/src/tasksuspend.c11
-rw-r--r--cpukit/score/include/rtems/score/threadimpl.h15
-rw-r--r--testsuites/tmtests/tm26/task1.c2
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
@@ -356,21 +356,6 @@ void _Thread_Set_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.
*
* This function maps thread IDs to thread control
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();