[rtems commit] score: Add optional _CPU_Get_thread_executing()

Sebastian Huber sebh at rtems.org
Mon Nov 7 06:45:40 UTC 2016


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Nov  4 13:28:23 2016 +0100

score: Add optional _CPU_Get_thread_executing()

---

 cpukit/score/cpu/no_cpu/rtems/score/cpuimpl.h | 12 ++++++++++++
 cpukit/score/include/rtems/score/percpu.h     | 18 +++++++++++++-----
 cpukit/score/src/threadhandler.c              |  3 ++-
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/cpukit/score/cpu/no_cpu/rtems/score/cpuimpl.h b/cpukit/score/cpu/no_cpu/rtems/score/cpuimpl.h
index 6b8b601..457ce4c 100644
--- a/cpukit/score/cpu/no_cpu/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/no_cpu/rtems/score/cpuimpl.h
@@ -5,6 +5,8 @@
  */
 
 /*
+ * Copyright (c) 2016 embedded brains GmbH.
+ *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
  * http://www.rtems.org/license/LICENSE.
@@ -21,6 +23,16 @@
 extern "C" {
 #endif
 
+/**
+ * @brief Optional method to get the executing thread.
+ *
+ * This is optional.  Not every CPU port needs this.  It is only an optional
+ * optimization variant.  In case this macro is undefined, the default
+ * implementation uses the per-CPU information and the current processor index
+ * to get the executing thread.
+ */
+#define _CPU_Get_thread_executing() ( _CPU_Per_CPU_current->executing )
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/cpukit/score/include/rtems/score/percpu.h b/cpukit/score/include/rtems/score/percpu.h
index 236cf6a..e3be0c8 100644
--- a/cpukit/score/include/rtems/score/percpu.h
+++ b/cpukit/score/include/rtems/score/percpu.h
@@ -17,7 +17,7 @@
 #ifndef _RTEMS_PERCPU_H
 #define _RTEMS_PERCPU_H
 
-#include <rtems/score/cpu.h>
+#include <rtems/score/cpuimpl.h>
 
 #if defined( ASM )
   #include <rtems/asm.h>
@@ -681,8 +681,15 @@ bool _Per_CPU_State_wait_for_non_initial_state(
   _Per_CPU_Get()->thread_dispatch_disable_level
 #define _Thread_Heir \
   _Per_CPU_Get()->heir
+
+#if defined(_CPU_Get_thread_executing)
+#define _Thread_Executing \
+  _CPU_Get_thread_executing()
+#else
 #define _Thread_Executing \
   _Per_CPU_Get_executing( _Per_CPU_Get() )
+#endif
+
 #define _ISR_Nest_level \
   _Per_CPU_Get()->isr_nest_level
 #define _CPU_Interrupt_stack_low \
@@ -695,9 +702,10 @@ bool _Per_CPU_State_wait_for_non_initial_state(
 /**
  * @brief Returns the thread control block of the executing thread.
  *
- * This function can be called in any context.  On SMP configurations
+ * This function can be called in any thread context.  On SMP configurations,
  * interrupts are disabled to ensure that the processor index is used
- * consistently.
+ * consistently if no CPU port specific method is available to get the
+ * executing thread.
  *
  * @return The thread control block of the executing thread.
  */
@@ -705,7 +713,7 @@ RTEMS_INLINE_ROUTINE struct _Thread_Control *_Thread_Get_executing( void )
 {
   struct _Thread_Control *executing;
 
-  #if defined( RTEMS_SMP )
+  #if defined(RTEMS_SMP) && !defined(_CPU_Get_thread_executing)
     ISR_Level level;
 
     _ISR_Local_disable( level );
@@ -713,7 +721,7 @@ RTEMS_INLINE_ROUTINE struct _Thread_Control *_Thread_Get_executing( void )
 
   executing = _Thread_Executing;
 
-  #if defined( RTEMS_SMP )
+  #if defined(RTEMS_SMP) && !defined(_CPU_Get_thread_executing)
     _ISR_Local_enable( level );
   #endif
 
diff --git a/cpukit/score/src/threadhandler.c b/cpukit/score/src/threadhandler.c
index 5d33f43..397e0cf 100644
--- a/cpukit/score/src/threadhandler.c
+++ b/cpukit/score/src/threadhandler.c
@@ -26,7 +26,7 @@
 
 void _Thread_Handler( void )
 {
-  Thread_Control  *executing = _Thread_Executing;
+  Thread_Control  *executing;
   ISR_Level        level;
   Per_CPU_Control *cpu_self;
 
@@ -36,6 +36,7 @@ void _Thread_Handler( void )
    * hook point where the port gets a shot at doing whatever it requires.
    */
   _Context_Initialization_at_thread_begin();
+  executing = _Thread_Executing;
 
   /* On SMP we enter _Thread_Handler() with interrupts disabled */
   _SMP_Assert( _ISR_Get_level() != 0 );



More information about the vc mailing list