You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/20 07:56:46 UTC

svn commit: r816984 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c

Author: mturk
Date: Sun Sep 20 05:56:46 2009
New Revision: 816984

URL: http://svn.apache.org/viewvc?rev=816984&view=rev
Log:
Few cosmetic fixes

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c?rev=816984&r1=816983&r2=816984&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c Sun Sep 20 05:56:46 2009
@@ -470,8 +470,7 @@
     wh[0] = sig_handle_event;
     wh[1] = CreateEvent(NULL, TRUE, TRUE, NULL);
     if (IS_VALID_HANDLE(wh[1])) {
-        sync.hEvent = wh[1];
-        nw++;
+        sync.hEvent = wh[nw++];
         cs = sig_pipe_connect(&sync);
     }
 
@@ -487,6 +486,9 @@
                  */
                 EnterCriticalSection(&signal_lock);
                 if (ACR_SIGNAL_NWAITERS() == 0) {
+                    /* The are no waiters for signal event
+                     * We have to deliver the signals.
+                     */
                     LeaveCriticalSection(&signal_lock);
                     rc = ACR_DeliverSignals();
                     if (rc == ACR_INCOMPLETE) {
@@ -550,7 +552,7 @@
             break;
         }
     }
-
+    CloseHandle(wh[1]);
     return 0;
 }
 
@@ -668,29 +670,32 @@
     int n = 0;
     LONG  mask;
     DWORD rc = ACR_EINTR;
-    /* We are invoked from one of the waiters.
-     *
-     */
 
-    if (!running)
+    if (!running) {
+        /* Signaling system is stopped.
+         * Notify the waiter that this is not restartable operation.
+         */
         return ACR_INCOMPLETE;
+    }
     EnterCriticalSection(&signal_lock);
-    if (ACR_SIGNAL_NWAITERS() == 0) {
-        /* Main signal dispatching.
-         *
+    if (!running) {
+        /* Someone has changed the running state while we
+         * were blocked on the signal lock.
+         * Since this is signal for process exit bail out.
          */
-
+        return ACR_INCOMPLETE;
+    }
+    if (ACR_SIGNAL_NWAITERS() == 0) {
         /* Getting here means we are the last thread that left
          * wait function for signal event.
-         * Make the signal event is back to non signaled state.
+         * Reset the signal event back to non signaled state.
          */
         ResetEvent(sig_raised_event);
     }
-    else {
-        /* Someone just entered while we obtained the lock
-         */
-    }
-
+   /* Dispatch the signals.
+    * Multiple threads can enter here depending on the number of waiters.
+    * Each thread will call one or more signal handlers.
+    */
     while ((mask = (current_signal_queue & ~current_signal_mask))) {
         int i;
         for (i = 1; i < ACR_NUMSIG; i++) {
@@ -711,25 +716,39 @@
                 if (sig != SIG_IGN && sig != SIG_ERR) {
                     LeaveCriticalSection(&signal_lock);
                     if (sig == SIG_DFL) {
+                        /* Execute default signal handler
+                         */
                         default_signal_handler(i);
                     }
                     else {
-                        /* ###: Can we have SIG_ACK and others here ?
+                        /* Execute registered handler
                          */
                         (*sig)(i);
                     }
+                    /* Obtain the lock again and break from the loop
+                     * in case signal mask has changed while we were
+                     * executing the handler.
+                     */
                     EnterCriticalSection(&signal_lock);
-                    break;
+                    if (!running) {
+                        /* Someone has changed the running state while we
+                         * were delivering the signal.
+                         */
+                        rc = ACR_INCOMPLETE;
+                    }
+                    else
+                        break;
                 }
             }
-            if (rc != ACR_EINTR)
+            if (rc != ACR_EINTR) {
+                /* Empty the signal queue so that other waiters
+                 * don't handle any more events.
+                 */
+                sigemptyset(&current_signal_queue);
                 break;
+            }
         }
     }
-    /* Empty queue in case we break before
-     * handling all events
-     */
-    sigemptyset(&current_signal_queue);
     LeaveCriticalSection(&signal_lock);
 
     return rc;