commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r815287 - in /commons/sandbox/runtime/trunk/src/main/native: include/arch/windows/acr_arch.h include/arch/windows/acr_arch_private.h os/win32/main.c os/win32/mutex.c os/win32/sema.c os/win32/signals.c
Date Tue, 15 Sep 2009 12:12:26 GMT
Author: mturk
Date: Tue Sep 15 12:12:25 2009
New Revision: 815287

URL: http://svn.apache.org/viewvc?rev=815287&view=rev
Log:
Move signal event creation to signals.c

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/signals.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=815287&r1=815286&r2=815287&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Tue Sep
15 12:12:25 2009
@@ -352,7 +352,7 @@
     char *d = NULL;
     if (s) {
         size_t size = strlen(s);
-        d = x_malloc(size + 2);
+        d = (char *)x_malloc(size + 2);
         if (d) {
             memcpy(d, s, size);
             d[size]   = '\0';
@@ -367,7 +367,7 @@
     wchar_t *d = NULL;
     if (s) {
         size_t size = wcslen(s);
-        d = x_malloc((size + 2) * sizeof(wchar_t));
+        d = (wchar_t *)x_malloc((size + 2) * sizeof(wchar_t));
         if (d) {
             memcpy(d, s, size * sizeof(wchar_t));
             d[size]   = L'\0';
@@ -476,7 +476,7 @@
 #define SIG_UNBLOCK 2
 #define SIG_SETMASK 3
 
-typedef LONG sigset_t;
+typedef volatile LONG sigset_t;
 
 typedef union sigval {
     /* Members as suggested by Annex C of POSIX 1003.1b. */
@@ -501,30 +501,30 @@
     void     (*sa_restorer)(void);
 };
 
-ACR_INLINE int sigaddset(sigset_t *set, int signo)
+static ACR_INLINE int sigaddset(sigset_t *set, int signo)
 {
 
     if (signo <= 0 || signo >= _NSIG) {
-        return ACR_EINVAL;
+        return ERROR_INVALID_PARAMETER;
     }
     *set |= (1 << ((signo)-1));
     return 0;
 }
 
-ACR_INLINE int sigdelset(sigset_t *set, int signo) {
+static ACR_INLINE int sigdelset(sigset_t *set, int signo) {
 
     if (signo <= 0 || signo >= _NSIG) {
-        return ACR_EINVAL;
+        return ERROR_INVALID_PARAMETER;
     }
     *set &= ~(1 << ((signo)-1));
     return 0;
 }
 
-ACR_INLINE int sigismember(const sigset_t *set, int signo)
+static ACR_INLINE int sigismember(const sigset_t *set, int signo)
 {
 
     if (signo <= 0 || signo >= _NSIG) {
-        return ACR_EINVAL;
+        return ERROR_INVALID_PARAMETER;
     }
     return (*set & (1 << ((signo)-1))) != 0;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=815287&r1=815286&r2=815287&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
Tue Sep 15 12:12:25 2009
@@ -137,10 +137,9 @@
 PSECURITY_ATTRIBUTES ACR_GetSaWithNullDacl(void);
 
 /**
- * Events from main.c
+ * Events from signals.c
  */
-extern HANDLE dll_psig_handle;
-extern HANDLE dll_auto_hevent;
+extern HANDLE sig_raised_event;
 
 /**
  * Local functions from signal.c
@@ -161,20 +160,20 @@
 
 DWORD        ACR_DeliverSignals(void);
 extern volatile LONG current_signal_listeners;
-#define ACR_SIGNAL_REGISTER() InterlockedIncrement(&current_signal_listeners)
-#define ACR_SIGNAL_RECEIVED() InterlockedDecrement(&current_signal_listeners)
+#define ACR_SIG_WAITER_INIT() InterlockedIncrement(&current_signal_listeners)
+#define ACR_SIG_WAITER_DONE() InterlockedDecrement(&current_signal_listeners)
 #define ACR_SIGNAL_NWAITERS() InterlockedCompareExchange(&current_signal_listeners, 0,
0)
 
-static ACR_INLINE DWORD ACR_WaitForObjectAndSignal(HANDLE handle, DWORD dwTimeout)
+static ACR_INLINE DWORD ACR_WaitForObjectOrSignal(HANDLE handle, DWORD dwTimeout)
 {
     DWORD  rc;
     HANDLE wh[2];
 
-    wh[0] = dll_psig_handle;
+    wh[0] = sig_raised_event;
     wh[1] = handle;
-    ACR_SIGNAL_REGISTER();
+    ACR_SIG_WAITER_INIT();
     rc =  WaitForMultipleObjectsEx(2, wh, FALSE, dwTimeout, TRUE);
-    ACR_SIGNAL_RECEIVED();
+    ACR_SIG_WAITER_DONE();
 
     return rc;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=815287&r1=815286&r2=815287&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Tue Sep 15 12:12:25 2009
@@ -37,8 +37,6 @@
 static WCHAR            dos_file_name[ACR_SBUFF_SIZ];
 static DWORD            dll_tls_index = TLS_OUT_OF_INDEXES;
 HANDLE                  dll_heap_handle = NULL;
-HANDLE                  dll_psig_handle = NULL;
-HANDLE                  dll_auto_hevent = NULL;
 
 static SYSTEM_INFO      osinf;
 static OSVERSIONINFOEXA osver;
@@ -328,32 +326,6 @@
         }
         i++;
     }
-    /*
-     * Create a simple unnamed signaling event.
-     * We use auto-reset event meaning that if multiple
-     * objects are waiting on that even only the one of them
-     * will be ever signaled.
-     * Always use WaitForMultipleObjects with this handle as
-     * first wait handle instead WaitForSingleObjects and
-     * call signal dispatching function when such event occurs.
-     */
-    dll_auto_hevent = CreateEvent(NULL, FALSE, FALSE, NULL);
-    if (IS_INVALID_HANDLE(dll_auto_hevent))
-        return ACR_GET_OS_ERROR();
-
-    /*
-     * Create a simple unnamed signaling event.
-     * We use mnual reset event meaning that if multiple
-     * objects are waiting on that even all of them
-     * will receive the signal.
-     * Always use WaitForMultipleObjects with this handle as
-     * first wait handle instead WaitForSingleObjects and
-     * call signal dispatching function when such event occurs.
-     */
-    dll_psig_handle = CreateEvent(NULL, TRUE, FALSE, NULL);
-    if (IS_INVALID_HANDLE(dll_psig_handle))
-        return ACR_GET_OS_ERROR();
-
     /* Do not display file not found messge boxes.
      * Return the error to the application instead
      */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c?rev=815287&r1=815286&r2=815287&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/mutex.c Tue Sep 15 12:12:25 2009
@@ -130,30 +130,29 @@
     }
     do {
         rc = 0;
-        ws = ACR_WaitForObjectAndSignal(m, INFINITE);
-        if (ws == WAIT_OBJECT_0) {
-            /* Signal event is set
-             * Get it's satus.
-             */
-            rc = ACR_DeliverSignals();
+        ws = ACR_WaitForObjectOrSignal(m, INFINITE);
+        switch (ws) {
+            case WAIT_IO_COMPLETION:
+            case WAIT_OBJECT_0 + 0:
+                /* Signal event is set.
+                 * Get it's satus.
+                 */
+                rc = ACR_DeliverSignals();
+            break;
+            case WAIT_ABANDONED_0 + 1:
+            case WAIT_OBJECT_0 + 1:
+                /* We got the lock */
+                return 0;
+            break;
+            case WAIT_FAILED:
+                /* We got the error while waiting
+                 */
+                rc = ACR_GET_OS_ERROR();
+            break;
+            default:
+                rc = ACR_ENOLOCK;
+            break;
         }
-        else if (ws == WAIT_OBJECT_0 + 1 || ws == WAIT_ABANDONED_0 + 1) {
-            /* We got the lock */
-            return 0;
-        }
-        else if (ws == WAIT_IO_COMPLETION) {
-            /* APC queued to this thread
-             * TODO: Deliver a signal
-             */
-            rc = ACR_TIMEUP;
-        }
-        else if (ws == WAIT_FAILED) {
-            /* We got the error while waiting
-             */
-            rc = ACR_GET_OS_ERROR();
-        }
-        else
-            rc = ACR_ENOLOCK;
     } while (rc == ACR_EINTR);
 
     return rc;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c?rev=815287&r1=815286&r2=815287&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sema.c Tue Sep 15 12:12:25 2009
@@ -167,31 +167,28 @@
 
     do {
         rc = 0;
-        ws = ACR_WaitForObjectAndSignal(s, INFINITE);
-
-        if (ws == WAIT_OBJECT_0) {
-            /* Signal event is set.
-             * Get it's satus.
-             */
-            rc = ACR_DeliverSignals();
-        }
-        else if (ws == WAIT_OBJECT_0 + 1) {
-            /* We got the lock */
-            return 0;
-        }
-        else if (ws == WAIT_IO_COMPLETION) {
-            /* APC queued to this thread
-             * TODO: Deliver a signal
-             */
-            rc = ACR_TIMEUP;
-        }
-        else if (ws == WAIT_FAILED) {
-            /* We got the error while waiting
-             */
-            rc = ACR_GET_OS_ERROR();
+        ws = ACR_WaitForObjectOrSignal(s, INFINITE);        
+        switch (ws) {
+            case WAIT_IO_COMPLETION:
+            case WAIT_OBJECT_0 + 0:
+                /* Signal event is set.
+                 * Get it's satus.
+                 */
+                rc = ACR_DeliverSignals();
+            break;
+            case WAIT_OBJECT_0 + 1:
+                /* We got the lock */
+                return 0;
+            break;
+            case WAIT_FAILED:
+                /* We got the error while waiting
+                 */
+                rc = ACR_GET_OS_ERROR();
+            break;
+            default:
+                rc = ACR_ENOLOCK;
+            break;
         }
-        else
-            rc = ACR_ENOLOCK;
     } while (rc == ACR_EINTR);
 
     return rc;

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=815287&r1=815286&r2=815287&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 Tue Sep 15 12:12:25 2009
@@ -50,16 +50,18 @@
 #define PIPE_TIMEOUT    1000
 
 static CRITICAL_SECTION signal_lock;
-int               dll_daemon_mode = 0;
-volatile sigset_t current_signal_mask;
-volatile sigset_t current_signal_queue;
-volatile LONG     current_signal_listeners;
+int             dll_daemon_mode = 0;
+static sigset_t current_signal_mask;
+static sigset_t current_signal_queue;
+volatile LONG   current_signal_listeners;
 
 static SIG_PF signal_handlers[ACR_NUMSIG];
-static volatile int signal_handlers_running;
+static volatile int running;
 
+HANDLE          sig_raised_event = NULL;
+static HANDLE   sig_handle_event = NULL;
 
-static HANDLE   sig_pipe_handle    = INVALID_HANDLE_VALUE;
+static HANDLE   sig_pipe_handle = INVALID_HANDLE_VALUE;
 static wchar_t  sig_pipe_name[64];
 static wchar_t  sig_pipe_salt[64];
 
@@ -196,12 +198,12 @@
     if (posix_signal) {
         /* Sync with signal callback handler */
         EnterCriticalSection(&signal_lock);
-        sigaddset(current_signal_queue, posix_signal);
+        sigaddset(&current_signal_queue, posix_signal);
         /* Fire the signal events.
          * The first locked listener will handle
          * the signal.
          */
-        SetEvent(dll_auto_hevent);
+        SetEvent(sig_handle_event);
         LeaveCriticalSection(&signal_lock);
         if (signal_handlers[posix_signal] == SIG_DFL) {
 #if defined(DEBUG)
@@ -238,12 +240,12 @@
         }
         /* Sync with signal handler */
         EnterCriticalSection(&signal_lock);
-        sigaddset(current_signal_queue, pd->msg.signal);
+        sigaddset(&current_signal_queue, pd->msg.signal);
         /* Notify the signal monitor thread.
          * Signal monitor thread will interrupt all waiters
          * and dispatch the signals if there are no waiters pending.
          */
-        SetEvent(dll_auto_hevent);
+        SetEvent(sig_handle_event);
         LeaveCriticalSection(&signal_lock);
 
         pd->msg.sender = GetCurrentProcessId();
@@ -341,7 +343,7 @@
     DWORD  cs;
     sig_pipe_data_t *pd;
 
-    wh[0] = dll_auto_hevent;
+    wh[0] = sig_handle_event;
     wh[1] = CreateEvent(NULL, TRUE, TRUE, NULL);
     if (IS_VALID_HANDLE(wh[1])) {
         sync.hEvent = wh[1];
@@ -349,7 +351,7 @@
         cs = sig_pipe_connect(&sync);
     }
 
-    while (signal_handlers_running) {
+    while (running) {
         rc = WaitForMultipleObjectsEx(nw, wh, FALSE, INFINITE, TRUE);
         switch (rc) {
             case WAIT_OBJECT_0 + 0:
@@ -363,7 +365,7 @@
                         /* Signal delivery requires the
                          * shutdown
                          */
-                        signal_handlers_running = 0;
+                        running = 0;
                     }
                 }
                 else {
@@ -376,7 +378,7 @@
                      * and the first one will handle the
                      * signal queue.
                      */
-                    SetEvent(dll_psig_handle);
+                    SetEvent(sig_raised_event);
                 }
 
             break;
@@ -416,7 +418,7 @@
             case WAIT_FAILED:
                 /* One of the events was closed
                  */
-                signal_handlers_running = 0;
+                running = 0;
             break;
         }
     }
@@ -432,7 +434,7 @@
     /* Guard against multiple invocations.
      * We might initialize twice; in daemon and in JVM again
      */
-    if (signal_handlers_running++) {
+    if (running++) {
         /* Second invocation.
          * Remove any previous handlers to our callback.
          */
@@ -450,9 +452,36 @@
         int rc = ACR_GET_OS_ERROR();
 
         DeleteCriticalSection(&signal_lock);
-        signal_handlers_running = 0;
+        running = 0;
         return rc;
     }
+    /*
+     * Create a simple unnamed signaling event.
+     * We use auto-reset event meaning that if multiple
+     * objects are waiting on that even only the one of them
+     * will be ever signaled.
+     * Always use WaitForMultipleObjects with this handle as
+     * first wait handle instead WaitForSingleObjects and
+     * call signal dispatching function when such event occurs.
+     */
+    sig_handle_event = CreateEvent(NULL, FALSE, FALSE, NULL);
+    if (IS_INVALID_HANDLE(sig_handle_event))
+        return ACR_GET_OS_ERROR();
+
+    /*
+     * Create a simple unnamed signaling event.
+     * We use mnual reset event meaning that if multiple
+     * objects are waiting on that even all of them
+     * will receive the signal.
+     * Always use WaitForMultipleObjects with this handle as
+     * first wait handle instead WaitForSingleObjects and
+     * call signal dispatching function when such event occurs.
+     */
+    sig_raised_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+    if (IS_INVALID_HANDLE(sig_raised_event))
+        return ACR_GET_OS_ERROR();
+
+    
     for (i = 0; i < ACR_NUMSIG; i++)
         signal_handlers[i] = SIG_IGN;
     signal_handlers[SIGBUS]  = default_signal_handler;
@@ -512,7 +541,7 @@
          * wait function for signal event.
          * Make the signal event is back to non signaled state.
          */
-        ResetEvent(dll_psig_handle);
+        ResetEvent(sig_raised_event);
     }
     else {
         /* Someone just entered while we obtained the lock
@@ -536,7 +565,7 @@
                 }
                 /* Remove the signal from the queue
                  */
-                sigdelset(current_signal_queue, i);
+                sigdelset(&current_signal_queue, i);
                 if (sig != SIG_IGN && sig != SIG_ERR) {
                     LeaveCriticalSection(&signal_lock);
                     (*sig)(i);
@@ -578,7 +607,7 @@
         current_signal_queue |= sigmask(signum);
         /* Wake up the monitor thread.
          */
-        SetEvent(dll_auto_hevent);
+        SetEvent(sig_handle_event);
         LeaveCriticalSection(&signal_lock);
 
         return 0;



Mime
View raw message