[rtems commit] posix: Store unblocked signals

Sebastian Huber sebh at rtems.org
Tue Dec 15 07:22:27 UTC 2015


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Dec 14 13:10:24 2015 +0100

posix: Store unblocked signals

Store the unblock signals to exploit the zero-initialization of the
thread control block.

---

 cpukit/posix/include/rtems/posix/threadsup.h |  4 ++--
 cpukit/posix/src/killinfo.c                  |  6 +++---
 cpukit/posix/src/psignal.c                   |  2 +-
 cpukit/posix/src/psignalchecksignal.c        | 10 +++++-----
 cpukit/posix/src/psignalclearsignals.c       | 10 +++++-----
 cpukit/posix/src/psignalunblockthread.c      |  4 ++--
 cpukit/posix/src/pthread.c                   |  4 +---
 cpukit/posix/src/pthreadsigmask.c            | 10 +++++-----
 8 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h
index ae12296..bf80c63 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -63,8 +63,8 @@ typedef struct {
    */
   Watchdog_Control        Sporadic_timer;
 
-  /** This is the set of signals which are currently blocked. */
-  sigset_t                signals_blocked;
+  /** This is the set of signals which are currently unblocked. */
+  sigset_t                signals_unblocked;
   /** This is the set of signals which are currently pending. */
   sigset_t                signals_pending;
 
diff --git a/cpukit/posix/src/killinfo.c b/cpukit/posix/src/killinfo.c
index a90f4b1..7f4adc7 100644
--- a/cpukit/posix/src/killinfo.c
+++ b/cpukit/posix/src/killinfo.c
@@ -52,7 +52,7 @@
  */
 
 #define _POSIX_signals_Is_interested( _api, _mask ) \
-  ( ~(_api)->signals_blocked & (_mask) )
+  ( (_api)->signals_unblocked & (_mask) )
 
 int killinfo(
   pid_t               pid,
@@ -153,7 +153,7 @@ int killinfo(
 
       #if defined(DEBUG_SIGNAL_PROCESSING)
         printk( "Waiting Thread=%p option=0x%08x mask=0x%08x blocked=0x%08x\n",
-          the_thread, the_thread->Wait.option, mask, api->signals_blocked);
+          the_thread, the_thread->Wait.option, mask, ~api->signals_unblocked);
       #endif
 
       /*
@@ -166,7 +166,7 @@ int killinfo(
        * Is this thread is blocked waiting for another signal but has
        * not blocked this one?
        */
-      if (~api->signals_blocked & mask)
+      if (api->signals_unblocked & mask)
         goto process_it;
     }
   }
diff --git a/cpukit/posix/src/psignal.c b/cpukit/posix/src/psignal.c
index d91a5bf..f00bcdb 100644
--- a/cpukit/posix/src/psignal.c
+++ b/cpukit/posix/src/psignal.c
@@ -144,7 +144,7 @@ void _POSIX_signals_Action_handler(
    */
   while (1) {
     _POSIX_signals_Acquire( &lock_context );
-      if ( !(~api->signals_blocked &
+      if ( !(api->signals_unblocked &
             (api->signals_pending | _POSIX_signals_Pending)) ) {
        _POSIX_signals_Release( &lock_context );
        break;
diff --git a/cpukit/posix/src/psignalchecksignal.c b/cpukit/posix/src/psignalchecksignal.c
index 2f9fe10..990bcc2 100644
--- a/cpukit/posix/src/psignalchecksignal.c
+++ b/cpukit/posix/src/psignalchecksignal.c
@@ -43,7 +43,7 @@ bool    _POSIX_signals_Check_signal(
 )
 {
   siginfo_t                   siginfo_struct;
-  sigset_t                    saved_signals_blocked;
+  sigset_t                    saved_signals_unblocked;
   Thread_Wait_information     stored_thread_wait_information;
   Thread_Control             *executing;
 
@@ -69,8 +69,8 @@ bool    _POSIX_signals_Check_signal(
   /*
    *  Block the signals requested in sa_mask
    */
-  saved_signals_blocked = api->signals_blocked;
-  api->signals_blocked |= _POSIX_signals_Vectors[ signo ].sa_mask;
+  saved_signals_unblocked = api->signals_unblocked;
+  api->signals_unblocked &= ~_POSIX_signals_Vectors[ signo ].sa_mask;
 
   executing = _Thread_Get_executing();
 
@@ -105,9 +105,9 @@ bool    _POSIX_signals_Check_signal(
           sizeof( executing->Wait ));
 
   /*
-   *  Restore the previous set of blocked signals
+   *  Restore the previous set of unblocked signals
    */
-  api->signals_blocked = saved_signals_blocked;
+  api->signals_unblocked = saved_signals_unblocked;
 
   return true;
 }
diff --git a/cpukit/posix/src/psignalclearsignals.c b/cpukit/posix/src/psignalclearsignals.c
index 18bdea5..c785255 100644
--- a/cpukit/posix/src/psignalclearsignals.c
+++ b/cpukit/posix/src/psignalclearsignals.c
@@ -46,7 +46,7 @@ bool _POSIX_signals_Clear_signals(
 )
 {
   sigset_t                    mask;
-  sigset_t                    signals_blocked;
+  sigset_t                    signals_unblocked;
   ISR_lock_Context            lock_context;
   bool                        do_callout;
   POSIX_signals_Siginfo_node *psiginfo;
@@ -60,9 +60,9 @@ bool _POSIX_signals_Clear_signals(
    */
 
   if ( check_blocked )
-    signals_blocked = ~api->signals_blocked;
+    signals_unblocked = api->signals_unblocked;
   else
-    signals_blocked = SIGNAL_ALL_MASK;
+    signals_unblocked = SIGNAL_ALL_MASK;
 
   /* XXX is this right for siginfo type signals? */
   /* XXX are we sure they can be cleared the same way? */
@@ -72,7 +72,7 @@ bool _POSIX_signals_Clear_signals(
   }
 
     if ( is_global ) {
-       if ( mask & (_POSIX_signals_Pending & signals_blocked) ) {
+       if ( mask & (_POSIX_signals_Pending & signals_unblocked) ) {
          if ( _POSIX_signals_Vectors[ signo ].sa_flags == SA_SIGINFO ) {
            psiginfo = (POSIX_signals_Siginfo_node *)
              _Chain_Get_unprotected( &_POSIX_signals_Siginfo[ signo ] );
@@ -95,7 +95,7 @@ bool _POSIX_signals_Clear_signals(
          do_callout = true;
        }
     } else {
-      if ( mask & (api->signals_pending & signals_blocked) ) {
+      if ( mask & (api->signals_pending & signals_unblocked) ) {
         api->signals_pending &= ~mask;
         do_callout = true;
       }
diff --git a/cpukit/posix/src/psignalunblockthread.c b/cpukit/posix/src/psignalunblockthread.c
index ff5a8fa..640c758 100644
--- a/cpukit/posix/src/psignalunblockthread.c
+++ b/cpukit/posix/src/psignalunblockthread.c
@@ -69,7 +69,7 @@ bool _POSIX_signals_Unblock_thread(
 
   if ( _States_Is_interruptible_signal( the_thread->current_state ) ) {
 
-    if ( (the_thread->Wait.option & mask) || (~api->signals_blocked & mask) ) {
+    if ( (the_thread->Wait.option & mask) || (api->signals_unblocked & mask) ) {
       the_thread->Wait.return_code = EINTR;
 
       the_info = (siginfo_t *) the_thread->Wait.return_argument;
@@ -96,7 +96,7 @@ bool _POSIX_signals_Unblock_thread(
   /*
    *  Thread is not waiting due to a sigwait.
    */
-  if ( ~api->signals_blocked & mask ) {
+  if ( api->signals_unblocked & mask ) {
 
     /*
      *  The thread is interested in this signal.  We are going
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index b8721f9..ee7da11 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -222,9 +222,7 @@ static bool _POSIX_Threads_Create_extension(
        #endif
   ) {
     executing_api = _Thread_Get_executing()->API_Extensions[ THREAD_API_POSIX ];
-    api->signals_blocked = executing_api->signals_blocked;
-  } else {
-    api->signals_blocked = SIGNAL_ALL_MASK;
+    api->signals_unblocked = executing_api->signals_unblocked;
   }
 
   _Thread_queue_Initialize( &api->Join_List, THREAD_QUEUE_DISCIPLINE_FIFO );
diff --git a/cpukit/posix/src/pthreadsigmask.c b/cpukit/posix/src/pthreadsigmask.c
index 7c2d99c..908ffd0 100644
--- a/cpukit/posix/src/pthreadsigmask.c
+++ b/cpukit/posix/src/pthreadsigmask.c
@@ -45,20 +45,20 @@ int pthread_sigmask(
   api = _Thread_Get_executing()->API_Extensions[ THREAD_API_POSIX ];
 
   if ( oset )
-    *oset = api->signals_blocked;
+    *oset = ~api->signals_unblocked;
 
   if ( !set )
     return 0;
 
   switch ( how ) {
     case SIG_BLOCK:
-      api->signals_blocked |= *set;
+      api->signals_unblocked &= ~*set;
       break;
     case SIG_UNBLOCK:
-      api->signals_blocked &= ~*set;
+      api->signals_unblocked |= *set;
       break;
     case SIG_SETMASK:
-      api->signals_blocked = *set;
+      api->signals_unblocked = ~*set;
       break;
     default:
       rtems_set_errno_and_return_minus_one( EINVAL );
@@ -68,7 +68,7 @@ int pthread_sigmask(
 
   /* XXX evaluate the new set */
 
-  if ( ~api->signals_blocked &
+  if ( api->signals_unblocked &
        (api->signals_pending | _POSIX_signals_Pending) ) {
     _Thread_Dispatch();
   }




More information about the vc mailing list