[xbuild] Add support for multi-targeting arbitrary frameworks.
[mono.git] / support / signal.c
index 11e60e1066e666811b567c914535a95cb20bb360..abd76382f0bc5646fdef31b4e1060f083f26a28d 100644 (file)
 #ifndef HOST_WIN32
 #include <sys/time.h>
 #include <sys/types.h>
+#if defined(__APPLE__)
+#include "fakepoll.h"
+#else
 #include <poll.h>
+#endif
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
@@ -120,6 +124,7 @@ int Mono_Posix_FromRealTimeSignum (int offset, int *r)
        #define mph_int_set(p,o,n) do { *(p) = n; } while (0)
 #endif
 
+#if HAVE_PSIGNAL
 int
 Mono_Posix_Syscall_psignal (int sig, const char* s)
 {
@@ -127,6 +132,7 @@ Mono_Posix_Syscall_psignal (int sig, const char* s)
        psignal (sig, s);
        return errno == 0 ? 0 : -1;
 }
+#endif  /* def HAVE_PSIGNAL */
 
 #define NUM_SIGNALS 64
 static signal_info signals[NUM_SIGNALS];
@@ -155,7 +161,7 @@ static void release_mutex (pthread_mutex_t *mutex)
 static inline int
 keep_trying (int r)
 {
-       return r == -1 && errno == EINTR && !mono_runtime_is_shutting_down();
+       return r == -1 && errno == EINTR;
 }
 
 static void
@@ -333,7 +339,7 @@ teardown_pipes (signal_info** signals, int count)
 }
 
 static int
-wait_for_any (signal_info** signals, int count, int *currfd, struct pollfd* fd_structs, int timeout)
+wait_for_any (signal_info** signals, int count, int *currfd, struct pollfd* fd_structs, int timeout, Mono_Posix_RuntimeIsShuttingDown shutting_down)
 {
        int r, idx;
        do {
@@ -345,7 +351,7 @@ wait_for_any (signal_info** signals, int count, int *currfd, struct pollfd* fd_s
                        ptv = &tv;
                }
                r = poll (fd_structs, count, timeout);
-       } while (keep_trying (r));
+       } while (keep_trying (r) && !shutting_down ());
 
        idx = -1;
        if (r == 0)
@@ -359,7 +365,7 @@ wait_for_any (signal_info** signals, int count, int *currfd, struct pollfd* fd_s
                                char c;
                                do {
                                        r = read (h->read_fd, &c, 1);
-                               } while (keep_trying (r));
+                               } while (keep_trying (r) && !shutting_down ());
                                if (idx == -1)
                                        idx = i;
                        }
@@ -375,7 +381,7 @@ wait_for_any (signal_info** signals, int count, int *currfd, struct pollfd* fd_s
  *          index into _signals array of signal that was generated on success
  */
 int
-Mono_Unix_UnixSignal_WaitAny (void** _signals, int count, int timeout /* milliseconds */)
+Mono_Unix_UnixSignal_WaitAny (void** _signals, int count, int timeout /* milliseconds */, Mono_Posix_RuntimeIsShuttingDown shutting_down)
 {
        int r;
        int currfd = 0;
@@ -394,7 +400,7 @@ Mono_Unix_UnixSignal_WaitAny (void** _signals, int count, int timeout /* millise
        release_mutex (&signals_mutex);
 
        if (r == 0) {
-               r = wait_for_any (signals, count, &currfd, &fd_structs[0], timeout);
+               r = wait_for_any (signals, count, &currfd, &fd_structs[0], timeout, shutting_down);
        }
 
        if (acquire_mutex (&signals_mutex) == -1)