[PATCH 1/4 v2] score: Simplify _Thread_Set_state()

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Apr 8 09:49:09 UTC 2015


---
 cpukit/score/include/rtems/score/threadimpl.h | 15 +++++----------
 cpukit/score/src/threadsetstate.c             | 16 +++++++++-------
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 551df45..f32362f 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -258,18 +258,13 @@ void _Thread_Clear_state(
 );
 
 /**
- *  @brief Sets the indicated @a state for @a the_thread.
+ * @brief Sets the specified thread state.
  *
- *  This routine sets the indicated @a state for @a the_thread.  It performs
- *  any necessary scheduling operations including the selection of
- *  a new heir thread.
- *
- *  @param[in] the_thread is the thread to set the state for.
- *  @param[in] state is the state to set the_thread to.
+ * In case the previous state is the ready state, then the thread is blocked by
+ * the scheduler.
  *
- *  - INTERRUPT LATENCY:
- *   + ready chain
- *   + select map
+ * @param[in] the_thread The thread.
+ * @param[in] state The state to set.  It must not be zero.
  */
 void _Thread_Set_state(
   Thread_Control *the_thread,
diff --git a/cpukit/score/src/threadsetstate.c b/cpukit/score/src/threadsetstate.c
index 02ee70e..2769711 100644
--- a/cpukit/score/src/threadsetstate.c
+++ b/cpukit/score/src/threadsetstate.c
@@ -22,7 +22,7 @@
 #endif
 
 #include <rtems/score/threadimpl.h>
-#include <rtems/score/isrlevel.h>
+#include <rtems/score/assert.h>
 #include <rtems/score/schedulerimpl.h>
 
 void _Thread_Set_state(
@@ -31,17 +31,19 @@ void _Thread_Set_state(
 )
 {
   ISR_lock_Context lock_context;
-  States_Control   current_state;
+  States_Control   previous_state;
+  States_Control   next_state;
+
+  _Assert( state != 0 );
 
   _Scheduler_Acquire( the_thread, &lock_context );
 
-  current_state = the_thread->current_state;
-  if ( _States_Is_ready( current_state ) ) {
-    the_thread->current_state = state;
+  previous_state = the_thread->current_state;
+  next_state = _States_Set( state, previous_state);
+  the_thread->current_state = next_state;
 
+  if ( _States_Is_ready( previous_state ) ) {
     _Scheduler_Block( the_thread );
-  } else {
-    the_thread->current_state = _States_Set( state, current_state);
   }
 
   _Scheduler_Release( the_thread, &lock_context );
-- 
1.8.4.5



More information about the devel mailing list