[rtems commit] rtems: Simplify signal handling

Sebastian Huber sebh at rtems.org
Sat Feb 20 14:25:22 UTC 2021


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Feb 16 08:15:10 2021 +0100

rtems: Simplify signal handling

Remove superfluous ASR_Information::signals_posted.  Move code out of
trivial inline functions.

Update #4244.

---

 cpukit/headers.am                       |  1 -
 cpukit/include/rtems/rtems/asrdata.h    |  2 -
 cpukit/include/rtems/rtems/asrimpl.h    | 90 ---------------------------------
 cpukit/include/rtems/rtems/signalimpl.h | 10 ----
 cpukit/rtems/src/signalcatch.c          | 18 ++++---
 cpukit/rtems/src/signalsend.c           | 23 ++++-----
 cpukit/rtems/src/taskmode.c             | 24 ++++-----
 spec/build/cpukit/librtemscpu.yml       |  1 -
 8 files changed, 33 insertions(+), 136 deletions(-)

diff --git a/cpukit/headers.am b/cpukit/headers.am
index cf7b715..169126b 100644
--- a/cpukit/headers.am
+++ b/cpukit/headers.am
@@ -250,7 +250,6 @@ include_rtems_rfs_HEADERS += include/rtems/rfs/rtems-rfs-mutex.h
 include_rtems_rfs_HEADERS += include/rtems/rfs/rtems-rfs-trace.h
 include_rtems_rtems_HEADERS += include/rtems/rtems/asr.h
 include_rtems_rtems_HEADERS += include/rtems/rtems/asrdata.h
-include_rtems_rtems_HEADERS += include/rtems/rtems/asrimpl.h
 include_rtems_rtems_HEADERS += include/rtems/rtems/attr.h
 include_rtems_rtems_HEADERS += include/rtems/rtems/attrimpl.h
 include_rtems_rtems_HEADERS += include/rtems/rtems/barrier.h
diff --git a/cpukit/include/rtems/rtems/asrdata.h b/cpukit/include/rtems/rtems/asrdata.h
index b0cb8f3..3f44d3b 100644
--- a/cpukit/include/rtems/rtems/asrdata.h
+++ b/cpukit/include/rtems/rtems/asrdata.h
@@ -42,8 +42,6 @@ typedef struct {
   rtems_asr_entry   handler;
   /** This field indicates if the task mode the signal will run with. */
   rtems_mode        mode_set;
-  /** This field indicates the signal set that is posted. */
-  rtems_signal_set  signals_posted;
   /** This field indicates the signal set that is pending. */
   rtems_signal_set  signals_pending;
 }   ASR_Information;
diff --git a/cpukit/include/rtems/rtems/asrimpl.h b/cpukit/include/rtems/rtems/asrimpl.h
deleted file mode 100644
index e936907..0000000
--- a/cpukit/include/rtems/rtems/asrimpl.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * @file
- *
- * @ingroup RTEMSImplClassicASR
- *
- * @brief This header file provides the implementation interfaces of
- *   the @ref RTEMSImplClassicASR support.
- */
-
-/* COPYRIGHT (c) 1989-2008.
- * On-Line Applications Research Corporation (OAR).
- *
- * 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.
- */
-
-#ifndef _RTEMS_RTEMS_ASRIMPL_H
-#define _RTEMS_RTEMS_ASRIMPL_H
-
-#include <rtems/rtems/asrdata.h>
-
-#include <string.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @defgroup RTEMSImplClassicASR Asynchronous Signal Routine (ASR)
- *
- * @ingroup RTEMSImplClassic
- *
- * @brief This group contains the implementation to support asynchronous signal
- *   routines.
- *
- * @{
- */
-
-/**
- *  @brief ASR_Initialize
- *
- *  This routine initializes the given RTEMS_ASR information record.
- */
-RTEMS_INLINE_ROUTINE void _ASR_Initialize (
-  ASR_Information *asr
-)
-{
-  memset(asr, 0, sizeof(*asr));
-}
-
-RTEMS_INLINE_ROUTINE rtems_signal_set _ASR_Swap_signals( ASR_Information *asr )
-{
-  rtems_signal_set new_signals_posted;
-
-  new_signals_posted   = asr->signals_pending;
-  asr->signals_pending = asr->signals_posted;
-  asr->signals_posted  = new_signals_posted;
-
-  return new_signals_posted;
-}
-
-RTEMS_INLINE_ROUTINE void _ASR_Post_signals(
-  rtems_signal_set  signals,
-  rtems_signal_set *signal_set
-)
-{
-  *signal_set |= signals;
-}
-
-RTEMS_INLINE_ROUTINE rtems_signal_set _ASR_Get_posted_signals(
-  ASR_Information *asr
-)
-{
-  rtems_signal_set signal_set;
-
-  signal_set = asr->signals_posted;
-  asr->signals_posted = 0;
-
-  return signal_set;
-}
-
-/**@}*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-/* end of include file */
diff --git a/cpukit/include/rtems/rtems/signalimpl.h b/cpukit/include/rtems/rtems/signalimpl.h
index 51f742c..db1ff71 100644
--- a/cpukit/include/rtems/rtems/signalimpl.h
+++ b/cpukit/include/rtems/rtems/signalimpl.h
@@ -31,18 +31,8 @@ extern "C" {
  * @ingroup RTEMSImplClassic
  *
  * @brief This group contains the Signal Manager implementation.
- *
- * @{
  */
 
-void _Signal_Action_handler(
-  Thread_Control   *executing,
-  Thread_Action    *action,
-  ISR_lock_Context *lock_context
-);
-
-/**@}*/
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/cpukit/rtems/src/signalcatch.c b/cpukit/rtems/src/signalcatch.c
index e4ff15f..8ee22e5 100644
--- a/cpukit/rtems/src/signalcatch.c
+++ b/cpukit/rtems/src/signalcatch.c
@@ -22,7 +22,6 @@
 #endif
 
 #include <rtems/rtems/signalimpl.h>
-#include <rtems/rtems/asrimpl.h>
 #include <rtems/rtems/tasksdata.h>
 #include <rtems/score/threadimpl.h>
 
@@ -41,12 +40,19 @@ rtems_status_code rtems_signal_catch(
   executing = _Thread_State_acquire_for_executing( &lock_context );
   api = executing->API_Extensions[ THREAD_API_RTEMS ];
   asr = &api->Signal;
+  asr->handler = asr_handler;
+  asr->mode_set = mode_set;
 
-  if ( asr_handler != NULL ) {
-    asr->mode_set = mode_set;
-    asr->handler = asr_handler;
-  } else {
-    _ASR_Initialize( asr );
+  if ( asr_handler == NULL ) {
+    Chain_Node *node;
+
+    asr->signals_pending = 0;
+    node = &api->Signal_action.Node;
+
+    if ( !_Chain_Is_node_off_chain( node ) ) {
+      _Chain_Extract_unprotected( node );
+      _Chain_Set_off_chain( node );
+    }
   }
 
   _Thread_State_release( executing, &lock_context );
diff --git a/cpukit/rtems/src/signalsend.c b/cpukit/rtems/src/signalsend.c
index fc8a66b..606ddfc 100644
--- a/cpukit/rtems/src/signalsend.c
+++ b/cpukit/rtems/src/signalsend.c
@@ -21,14 +21,13 @@
 #endif
 
 #include <rtems/rtems/signalimpl.h>
-#include <rtems/rtems/asrimpl.h>
 #include <rtems/rtems/tasksdata.h>
 #include <rtems/score/threaddispatch.h>
 #include <rtems/score/threadimpl.h>
 
 #include <rtems/sysinit.h>
 
-void _Signal_Action_handler(
+static void _Signal_Action_handler(
   Thread_Control   *executing,
   Thread_Action    *action,
   ISR_lock_Context *lock_context
@@ -41,23 +40,20 @@ void _Signal_Action_handler(
 
   (void) action;
 
-  /*
-   *  Signal Processing
-   */
-
   api = executing->API_Extensions[ THREAD_API_RTEMS ];
   asr = &api->Signal;
-  signal_set = _ASR_Get_posted_signals( asr );
 
-  if ( signal_set == 0 ) {
-    return;
-  }
+  /* Get and clear the pending signals */
+  signal_set = asr->signals_pending;
+  _Assert( signal_set != 0 );
+  asr->signals_pending = 0;
 
   _Thread_State_release( executing, lock_context );
 
   rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
 
-  (*asr->handler)( signal_set );
+  /* Call the ASR handler in the ASR processing mode */
+  ( *asr->handler )( signal_set );
 
   rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
 
@@ -98,10 +94,12 @@ rtems_status_code rtems_signal_send(
     return RTEMS_NOT_DEFINED;
   }
 
+  /* Make the signals of the set pending */
+  asr->signals_pending |= signal_set;
+
   if ( asr->is_enabled ) {
     Per_CPU_Control *cpu_self;
 
-    _ASR_Post_signals( signal_set, &asr->signals_posted );
     _Thread_Add_post_switch_action(
       the_thread,
       &api->Signal_action,
@@ -111,7 +109,6 @@ rtems_status_code rtems_signal_send(
     _Thread_State_release( the_thread, &lock_context );
     _Thread_Dispatch_enable( cpu_self );
   } else {
-    _ASR_Post_signals( signal_set, &asr->signals_pending );
     _Thread_State_release( the_thread, &lock_context );
   }
 
diff --git a/cpukit/rtems/src/taskmode.c b/cpukit/rtems/src/taskmode.c
index cbf8c06..2490536 100644
--- a/cpukit/rtems/src/taskmode.c
+++ b/cpukit/rtems/src/taskmode.c
@@ -21,7 +21,6 @@
 #endif
 
 #include <rtems/rtems/tasksdata.h>
-#include <rtems/rtems/asrimpl.h>
 #include <rtems/rtems/modesimpl.h>
 #include <rtems/rtems/signalimpl.h>
 #include <rtems/score/schedulerimpl.h>
@@ -125,21 +124,20 @@ rtems_status_code rtems_task_mode(
    */
   needs_asr_dispatching = false;
   if ( mask & RTEMS_ASR_MASK ) {
-    bool is_asr_enabled = !_Modes_Is_asr_disabled( mode_set );
+    bool prev_asr_is_enabled;
 
     _Thread_State_acquire( executing, &lock_context );
 
-    if ( is_asr_enabled != asr->is_enabled ) {
-      asr->is_enabled = is_asr_enabled;
-
-      if ( _ASR_Swap_signals( asr ) != 0 ) {
-        needs_asr_dispatching = true;
-        _Thread_Add_post_switch_action(
-          executing,
-          &api->Signal_action,
-          _Signal_Action_handler
-        );
-      }
+    prev_asr_is_enabled = asr->is_enabled;
+    asr->is_enabled = !_Modes_Is_asr_disabled( mode_set );
+
+    if (
+      !prev_asr_is_enabled &&
+        asr->is_enabled &&
+        asr->signals_pending != 0
+    ) {
+      needs_asr_dispatching = true;
+      _Thread_Append_post_switch_action( executing, &api->Signal_action );
     }
 
     _Thread_State_release( executing, &lock_context );
diff --git a/spec/build/cpukit/librtemscpu.yml b/spec/build/cpukit/librtemscpu.yml
index f54673f..3d1ec08 100644
--- a/spec/build/cpukit/librtemscpu.yml
+++ b/spec/build/cpukit/librtemscpu.yml
@@ -265,7 +265,6 @@ install:
   source:
   - cpukit/include/rtems/rtems/asr.h
   - cpukit/include/rtems/rtems/asrdata.h
-  - cpukit/include/rtems/rtems/asrimpl.h
   - cpukit/include/rtems/rtems/attr.h
   - cpukit/include/rtems/rtems/attrimpl.h
   - cpukit/include/rtems/rtems/barrier.h



More information about the vc mailing list