[PATCH 07/14] rtems: Use thread state lock for signals

Sebastian Huber sebastian.huber at embedded-brains.de
Wed May 11 13:23:34 UTC 2016


---
 cpukit/rtems/include/rtems/rtems/asr.h     |  3 --
 cpukit/rtems/include/rtems/rtems/asrimpl.h | 61 ++++--------------------------
 cpukit/rtems/src/signalcatch.c             | 17 ++++-----
 cpukit/rtems/src/signalsend.c              |  8 ++--
 cpukit/rtems/src/taskmode.c                |  6 ++-
 cpukit/rtems/src/tasks.c                   | 48 +----------------------
 cpukit/score/include/rtems/score/thread.h  |  1 +
 7 files changed, 24 insertions(+), 120 deletions(-)

diff --git a/cpukit/rtems/include/rtems/rtems/asr.h b/cpukit/rtems/include/rtems/rtems/asr.h
index 4563750..edd5e2f 100644
--- a/cpukit/rtems/include/rtems/rtems/asr.h
+++ b/cpukit/rtems/include/rtems/rtems/asr.h
@@ -22,7 +22,6 @@
 #ifndef _RTEMS_RTEMS_ASR_H
 #define _RTEMS_RTEMS_ASR_H
 
-#include <rtems/score/isrlock.h>
 #include <rtems/rtems/modes.h>
 
 #ifdef __cplusplus
@@ -75,8 +74,6 @@ typedef struct {
   rtems_signal_set  signals_pending;
   /** This field indicates if nest level of signals being processed */
   uint32_t          nest_level;
-  /** Lock to protect this structure */
-  ISR_LOCK_MEMBER(  Lock )
 }   ASR_Information;
 
 /*
diff --git a/cpukit/rtems/include/rtems/rtems/asrimpl.h b/cpukit/rtems/include/rtems/rtems/asrimpl.h
index 892c58c..141c34d 100644
--- a/cpukit/rtems/include/rtems/rtems/asrimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/asrimpl.h
@@ -19,6 +19,8 @@
 
 #include <rtems/rtems/asr.h>
 
+#include <string.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -40,48 +42,7 @@ RTEMS_INLINE_ROUTINE void _ASR_Initialize (
   ASR_Information *asr
 )
 {
-  asr->is_enabled      = false;
-  asr->handler         = NULL;
-  asr->mode_set        = RTEMS_DEFAULT_MODES;
-  asr->signals_posted  = 0;
-  asr->signals_pending = 0;
-  asr->nest_level      = 0;
-}
-
-RTEMS_INLINE_ROUTINE void _ASR_Create( ASR_Information *asr )
-{
-  _ISR_lock_Initialize( &asr->Lock, "ASR" );
-  RTEMS_STATIC_ASSERT( RTEMS_DEFAULT_MODES == 0, _ASR_Create_mode_set );
-}
-
-RTEMS_INLINE_ROUTINE void _ASR_Destroy( ASR_Information *asr )
-{
-  _ISR_lock_Destroy( &asr->Lock );
-}
-
-RTEMS_INLINE_ROUTINE void _ASR_Acquire_critical(
-  ASR_Information  *asr,
-  ISR_lock_Context *lock_context
-)
-{
-  _ISR_lock_Acquire( &asr->Lock, lock_context );
-}
-
-RTEMS_INLINE_ROUTINE void _ASR_Acquire(
-  ASR_Information  *asr,
-  ISR_lock_Context *lock_context
-)
-{
-  _ISR_lock_ISR_disable( lock_context );
-  _ASR_Acquire_critical( asr, lock_context );
-}
-
-RTEMS_INLINE_ROUTINE void _ASR_Release(
-  ASR_Information  *asr,
-  ISR_lock_Context *lock_context
-)
-{
-  _ISR_lock_Release_and_ISR_enable( &asr->Lock, lock_context );
+  memset(asr, 0, sizeof(*asr));
 }
 
 /**
@@ -100,13 +61,10 @@ RTEMS_INLINE_ROUTINE bool _ASR_Is_null_handler (
 RTEMS_INLINE_ROUTINE rtems_signal_set _ASR_Swap_signals( ASR_Information *asr )
 {
   rtems_signal_set new_signals_posted;
-  ISR_lock_Context lock_context;
 
-  _ASR_Acquire( asr, &lock_context );
-    new_signals_posted   = asr->signals_pending;
-    asr->signals_pending = asr->signals_posted;
-    asr->signals_posted  = new_signals_posted;
-  _ASR_Release( asr, &lock_context );
+  new_signals_posted   = asr->signals_pending;
+  asr->signals_pending = asr->signals_posted;
+  asr->signals_posted  = new_signals_posted;
 
   return new_signals_posted;
 }
@@ -124,12 +82,9 @@ RTEMS_INLINE_ROUTINE rtems_signal_set _ASR_Get_posted_signals(
 )
 {
   rtems_signal_set signal_set;
-  ISR_lock_Context lock_context;
 
-  _ASR_Acquire( asr, &lock_context );
-    signal_set = asr->signals_posted;
-    asr->signals_posted = 0;
-  _ASR_Release( asr, &lock_context );
+  signal_set = asr->signals_posted;
+  asr->signals_posted = 0;
 
   return signal_set;
 }
diff --git a/cpukit/rtems/src/signalcatch.c b/cpukit/rtems/src/signalcatch.c
index e300890..9c264b7 100644
--- a/cpukit/rtems/src/signalcatch.c
+++ b/cpukit/rtems/src/signalcatch.c
@@ -25,6 +25,8 @@
 #include <rtems/score/assert.h>
 #include <rtems/score/threadimpl.h>
 
+RTEMS_STATIC_ASSERT( RTEMS_DEFAULT_MODES == 0, _ASR_Create_mode_set );
+
 void _Signal_Action_handler(
   Thread_Control   *executing,
   Thread_Action    *action,
@@ -37,19 +39,17 @@ void _Signal_Action_handler(
   Modes_Control      prev_mode;
 
   (void) action;
-  _Thread_State_release( executing, lock_context );
-
-  api = executing->API_Extensions[ THREAD_API_RTEMS ];
-  if ( !api )
-    return;
 
   /*
    *  Signal Processing
    */
 
+  api = executing->API_Extensions[ THREAD_API_RTEMS ];
   asr = &api->Signal;
   signal_set = _ASR_Get_posted_signals( asr );
 
+  _Thread_State_release( executing, lock_context );
+
   if ( signal_set == 0 ) {
     return;
   }
@@ -73,13 +73,10 @@ rtems_status_code rtems_signal_catch(
   ASR_Information    *asr;
   ISR_lock_Context    lock_context;
 
-  _ISR_lock_ISR_disable( &lock_context );
-  executing = _Thread_Executing;
+  executing = _Thread_State_acquire_for_executing( &lock_context );
   api = executing->API_Extensions[ THREAD_API_RTEMS ];
   asr = &api->Signal;
 
-  _ASR_Acquire_critical( asr, &lock_context );
-
   if ( !_ASR_Is_null_handler( asr_handler ) ) {
     asr->mode_set = mode_set;
     asr->handler = asr_handler;
@@ -87,7 +84,7 @@ rtems_status_code rtems_signal_catch(
     _ASR_Initialize( asr );
   }
 
-  _ASR_Release( asr, &lock_context );
+  _Thread_State_release( executing, &lock_context );
   return RTEMS_SUCCESSFUL;
 }
 
diff --git a/cpukit/rtems/src/signalsend.c b/cpukit/rtems/src/signalsend.c
index abf3d5d..9be8460 100644
--- a/cpukit/rtems/src/signalsend.c
+++ b/cpukit/rtems/src/signalsend.c
@@ -51,10 +51,10 @@ rtems_status_code rtems_signal_send(
   api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
   asr = &api->Signal;
 
-  _ASR_Acquire_critical( asr, &lock_context );
+  _Thread_State_acquire_critical( the_thread, &lock_context );
 
   if ( _ASR_Is_null_handler( asr->handler ) ) {
-    _ASR_Release( asr, &lock_context );
+    _Thread_State_release( the_thread, &lock_context );
     return RTEMS_NOT_DEFINED;
   }
 
@@ -62,8 +62,6 @@ rtems_status_code rtems_signal_send(
     Per_CPU_Control *cpu_self;
 
     _ASR_Post_signals( signal_set, &asr->signals_posted );
-    _ASR_Release( asr, &lock_context );
-    _Thread_State_acquire( the_thread, &lock_context );
     _Thread_Add_post_switch_action(
       the_thread,
       &api->Signal_action,
@@ -74,7 +72,7 @@ rtems_status_code rtems_signal_send(
     _Thread_Dispatch_enable( cpu_self );
   } else {
     _ASR_Post_signals( signal_set, &asr->signals_pending );
-    _ASR_Release( asr, &lock_context );
+    _Thread_State_release( the_thread, &lock_context );
   }
 
   return RTEMS_SUCCESSFUL;
diff --git a/cpukit/rtems/src/taskmode.c b/cpukit/rtems/src/taskmode.c
index 2f8f354..131632d 100644
--- a/cpukit/rtems/src/taskmode.c
+++ b/cpukit/rtems/src/taskmode.c
@@ -98,20 +98,22 @@ rtems_status_code rtems_task_mode(
   if ( mask & RTEMS_ASR_MASK ) {
     bool is_asr_enabled = !_Modes_Is_asr_disabled( mode_set );
 
+    _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_State_acquire( executing, &lock_context );
         _Thread_Add_post_switch_action(
           executing,
           &api->Signal_action,
           _Signal_Action_handler
         );
-        _Thread_State_release( executing, &lock_context );
       }
     }
+
+    _Thread_State_release( executing, &lock_context );
   }
 
   if ( preempt_enabled || needs_asr_dispatching ) {
diff --git a/cpukit/rtems/src/tasks.c b/cpukit/rtems/src/tasks.c
index 56b2455..b4ebff6 100644
--- a/cpukit/rtems/src/tasks.c
+++ b/cpukit/rtems/src/tasks.c
@@ -20,7 +20,6 @@
 
 #include <rtems/config.h>
 #include <rtems/sysinit.h>
-#include <rtems/rtems/asrimpl.h>
 #include <rtems/rtems/eventimpl.h>
 #include <rtems/rtems/tasksimpl.h>
 #include <rtems/score/threadimpl.h>
@@ -28,37 +27,6 @@
 
 Thread_Information _RTEMS_tasks_Information;
 
-/*
- *  _RTEMS_tasks_Create_extension
- *
- *  This routine is an extension routine that is invoked as part
- *  of creating any type of task or thread in the system.  If the
- *  task is created via another API, then this routine is invoked
- *  and this API given the opportunity to initialize its extension
- *  area.
- */
-
-static bool _RTEMS_tasks_Create_extension(
-  Thread_Control *executing,
-  Thread_Control *created
-)
-{
-  RTEMS_API_Control *api;
-
-  api = created->API_Extensions[ THREAD_API_RTEMS ];
-
-  _ASR_Create( &api->Signal );
-
-  return true;
-}
-
-/*
- *  _RTEMS_tasks_Start_extension
- *
- *  This extension routine is invoked when a task is started for the
- *  first time.
- */
-
 static void _RTEMS_tasks_Start_extension(
   Thread_Control *executing,
   Thread_Control *started
@@ -72,24 +40,10 @@ static void _RTEMS_tasks_Start_extension(
   _Event_Initialize( &api->System_event );
 }
 
-static void _RTEMS_tasks_Delete_extension(
-  Thread_Control *executing,
-  Thread_Control *deleted
-)
-{
-  RTEMS_API_Control *api;
-
-  api = deleted->API_Extensions[ THREAD_API_RTEMS ];
-
-  _ASR_Destroy( &api->Signal );
-}
-
 User_extensions_Control _RTEMS_tasks_User_extensions = {
   .Callouts = {
-    .thread_create  = _RTEMS_tasks_Create_extension,
     .thread_start   = _RTEMS_tasks_Start_extension,
-    .thread_restart = _RTEMS_tasks_Start_extension,
-    .thread_delete  = _RTEMS_tasks_Delete_extension
+    .thread_restart = _RTEMS_tasks_Start_extension
   }
 };
 
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index d4ca505..d2a6d4b 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -718,6 +718,7 @@ struct _Thread_Control {
    * The lock of this thread queue is used for various purposes.  It protects
    * the following fields
    *
+   * - RTEMS_API_Control::Signal, and
    * - Thread_Control::Post_switch_actions.
    *
    * @see _Thread_State_acquire().
-- 
1.8.4.5




More information about the devel mailing list