[rtems commit] score: Return prev state in thread state set/clear

Sebastian Huber sebh at rtems.org
Thu Apr 9 11:53:01 UTC 2015


Module:    rtems
Branch:    master
Commit:    342708b9834096a2c8a9ad604626c82da6fb956c
Changeset: http://git.rtems.org/rtems/commit/?id=342708b9834096a2c8a9ad604626c82da6fb956c

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Mar 26 21:45:20 2015 +0100

score: Return prev state in thread state set/clear

---

 cpukit/score/include/rtems/score/threadimpl.h | 20 +++++++++++---------
 cpukit/score/src/threadclearstate.c           | 22 +++++++++++++++-------
 cpukit/score/src/threadsetstate.c             |  4 +++-
 3 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index f32362f..65625b6 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -242,17 +242,17 @@ void _Thread_Ready(
 );
 
 /**
- *  @brief Clears the indicated STATES for @a the_thread.
+ * @brief Clears the specified thread state.
  *
- *  This routine clears the indicated STATES for @a the_thread.  It performs
- *  any necessary scheduling operations including the selection of
- *  a new heir thread.
+ * In case the previous state is a non-ready state and the next state is the
+ * ready state, then the thread is unblocked by the scheduler.
  *
- *  - INTERRUPT LATENCY:
- *    + priority map
- *    + select heir
+ * @param[in] the_thread The thread.
+ * @param[in] state The state to clear.  It must not be zero.
+ *
+ * @return The previous state.
  */
-void _Thread_Clear_state(
+States_Control _Thread_Clear_state(
   Thread_Control *the_thread,
   States_Control  state
 );
@@ -265,8 +265,10 @@ void _Thread_Clear_state(
  *
  * @param[in] the_thread The thread.
  * @param[in] state The state to set.  It must not be zero.
+ *
+ * @return The previous state.
  */
-void _Thread_Set_state(
+States_Control _Thread_Set_state(
   Thread_Control *the_thread,
   States_Control  state
 );
diff --git a/cpukit/score/src/threadclearstate.c b/cpukit/score/src/threadclearstate.c
index c60fb8f..ae54e3a 100644
--- a/cpukit/score/src/threadclearstate.c
+++ b/cpukit/score/src/threadclearstate.c
@@ -19,27 +19,35 @@
 #endif
 
 #include <rtems/score/threadimpl.h>
+#include <rtems/score/assert.h>
 #include <rtems/score/schedulerimpl.h>
 
-void _Thread_Clear_state(
+States_Control _Thread_Clear_state(
   Thread_Control *the_thread,
   States_Control  state
 )
 {
   ISR_lock_Context lock_context;
-  States_Control   current_state;
+  States_Control   previous_state;
+
+  _Assert( state != 0 );
 
   _Scheduler_Acquire( the_thread, &lock_context );
 
-  current_state = the_thread->current_state;
-  if ( current_state & state ) {
-    current_state =
-    the_thread->current_state = _States_Clear( state, current_state );
+  previous_state = the_thread->current_state;
+
+  if ( ( previous_state & state ) != 0 ) {
+    States_Control next_state;
 
-    if ( _States_Is_ready( current_state ) ) {
+    next_state = _States_Clear( state, previous_state );
+    the_thread->current_state = next_state;
+
+    if ( _States_Is_ready( next_state ) ) {
       _Scheduler_Unblock( the_thread );
     }
   }
 
   _Scheduler_Release( the_thread, &lock_context );
+
+  return previous_state;
 }
diff --git a/cpukit/score/src/threadsetstate.c b/cpukit/score/src/threadsetstate.c
index 2769711..5112827 100644
--- a/cpukit/score/src/threadsetstate.c
+++ b/cpukit/score/src/threadsetstate.c
@@ -25,7 +25,7 @@
 #include <rtems/score/assert.h>
 #include <rtems/score/schedulerimpl.h>
 
-void _Thread_Set_state(
+States_Control _Thread_Set_state(
   Thread_Control *the_thread,
   States_Control  state
 )
@@ -47,4 +47,6 @@ void _Thread_Set_state(
   }
 
   _Scheduler_Release( the_thread, &lock_context );
+
+  return previous_state;
 }



More information about the vc mailing list