[PATCH 3/5] rtems: Add signal post switch extension on the fly

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Dec 3 11:54:09 UTC 2012


---
 cpukit/rtems/src/signalcatch.c |   44 +++++++++++++++++++++++++++++++++++
 cpukit/rtems/src/tasks.c       |   50 ----------------------------------------
 2 files changed, 44 insertions(+), 50 deletions(-)

diff --git a/cpukit/rtems/src/signalcatch.c b/cpukit/rtems/src/signalcatch.c
index 4170b61..5cc4218 100644
--- a/cpukit/rtems/src/signalcatch.c
+++ b/cpukit/rtems/src/signalcatch.c
@@ -21,8 +21,50 @@
 #include <rtems/rtems/modes.h>
 #include <rtems/rtems/signal.h>
 #include <rtems/score/thread.h>
+#include <rtems/score/apiext.h>
 #include <rtems/rtems/tasks.h>
 
+static void _RTEMS_signal_Post_switch_hook( Thread_Control *executing )
+{
+  ISR_Level          level;
+  RTEMS_API_Control *api;
+  ASR_Information   *asr;
+  rtems_signal_set   signal_set;
+  Modes_Control      prev_mode;
+
+  api = executing->API_Extensions[ THREAD_API_RTEMS ];
+  if ( !api )
+    return;
+
+  /*
+   *  Signal Processing
+   */
+
+  asr = &api->Signal;
+
+  _ISR_Disable( level );
+    signal_set = asr->signals_posted;
+    asr->signals_posted = 0;
+  _ISR_Enable( level );
+
+
+  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
+    return;
+
+  asr->nest_level += 1;
+  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
+
+  (*asr->handler)( signal_set );
+
+  asr->nest_level -= 1;
+  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
+
+}
+
+static API_extensions_Post_switch_control _RTEMS_signal_Post_switch = {
+  .hook = _RTEMS_signal_Post_switch_hook
+};
+
 /*
  *  rtems_signal_catch
  *
@@ -55,6 +97,8 @@ rtems_status_code rtems_signal_catch(
   _Thread_Disable_dispatch(); /* cannot reschedule while */
                               /*   the thread is inconsistent */
 
+  _API_extensions_Add_post_switch( &_RTEMS_signal_Post_switch );
+
   if ( !_ASR_Is_null_handler( asr_handler ) ) {
     asr->mode_set = mode_set;
     asr->handler = asr_handler;
diff --git a/cpukit/rtems/src/tasks.c b/cpukit/rtems/src/tasks.c
index 36142d5..a6f40e3 100644
--- a/cpukit/rtems/src/tasks.c
+++ b/cpukit/rtems/src/tasks.c
@@ -162,51 +162,6 @@ static void _RTEMS_tasks_Switch_extension(
   }
 }
 
-/*
- *  _RTEMS_tasks_Post_switch_extension
- *
- *  This extension routine is invoked at each context switch.
- */
-
-static void _RTEMS_tasks_Post_switch_extension(
-  Thread_Control *executing
-)
-{
-  ISR_Level          level;
-  RTEMS_API_Control *api;
-  ASR_Information   *asr;
-  rtems_signal_set   signal_set;
-  Modes_Control      prev_mode;
-
-  api = executing->API_Extensions[ THREAD_API_RTEMS ];
-  if ( !api )
-    return;
-
-  /*
-   *  Signal Processing
-   */
-
-  asr = &api->Signal;
-
-  _ISR_Disable( level );
-    signal_set = asr->signals_posted;
-    asr->signals_posted = 0;
-  _ISR_Enable( level );
-
-
-  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
-    return;
-
-  asr->nest_level += 1;
-  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
-
-  (*asr->handler)( signal_set );
-
-  asr->nest_level -= 1;
-  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
-
-}
-
 API_extensions_Control _RTEMS_tasks_API_extensions = {
   #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
     .predriver_hook = NULL,
@@ -214,10 +169,6 @@ API_extensions_Control _RTEMS_tasks_API_extensions = {
   .postdriver_hook = _RTEMS_tasks_Initialize_user_tasks
 };
 
-API_extensions_Post_switch_control _RTEMS_tasks_API_extensions_post_switch = {
-  .hook = _RTEMS_tasks_Post_switch_extension
-};
-
 User_extensions_Control _RTEMS_tasks_User_extensions = {
   { NULL, NULL },
   { { NULL, NULL }, _RTEMS_tasks_Switch_extension },
@@ -267,7 +218,6 @@ void _RTEMS_tasks_Manager_initialization(void)
   _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
 
   _API_extensions_Add( &_RTEMS_tasks_API_extensions );
-  _API_extensions_Add_post_switch( &_RTEMS_tasks_API_extensions_post_switch );
 
   /*
    *  Register the MP Process Packet routine.
-- 
1.7.7




More information about the devel mailing list