[PATCH 4/5] rtems: Atomically suspend/resume tasks

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Mar 31 06:00:06 UTC 2015


---
 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 86a22e1..ed06a22 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 f8c43a7..ae7995a 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 dcbb71f..fa4e434 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -363,21 +363,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 5d74872..6cec7da 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();
-- 
1.8.4.5




More information about the devel mailing list