From 77ef2c253b58a442f36bff66f06be3d1884f980f Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Tue, 12 Feb 2008 16:54:18 +0000 Subject: [PATCH] * signal.c: SLES9 has glib 2.2, so we can't rely on g_atomic_int_*(). Provide a fallback mechanism between using Mono's atomic.h, glib 2.4 functions, and horribly unsafe-but-no-alternative code. svn path=/trunk/mono/; revision=95526 --- support/ChangeLog | 6 ++++++ support/signal.c | 27 ++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/support/ChangeLog b/support/ChangeLog index 76d9c80d422..1b719cb6d07 100644 --- a/support/ChangeLog +++ b/support/ChangeLog @@ -1,3 +1,9 @@ +2008-02-12 Jonathan Pryor + + * signal.c: SLES9 has glib 2.2, so we can't rely on g_atomic_int_*(). + Provide a fallback mechanism between using Mono's atomic.h, glib 2.4 + functions, and horribly unsafe-but-no-alternative code. + 2008-02-12 Jonathan Pryor * signal.c: Fix another build break; g_atomic_int_set() (part of GLib 2.10) diff --git a/support/signal.c b/support/signal.c index 79beffcc75b..4ba92742af2 100644 --- a/support/signal.c +++ b/support/signal.c @@ -21,6 +21,7 @@ #include #include #include +#include #endif G_BEGIN_DECLS @@ -55,6 +56,22 @@ Mono_Posix_Stdlib_InvokeSignalHandler (int signum, void *handler) #ifndef PLATFORM_WIN32 +#ifdef WAPI_ATOMIC_ASM + #define mph_int_get(p) InterlockedExchangeAdd ((p), 0) + #define mph_int_inc(p) InterlockedIncrement ((p)) + #define mph_int_set(p,o,n) InterlockedExchange ((p), (n)) +#elif GLIB_CHECK_VERSION(2,4,0) + #define mph_int_get(p) g_atomic_int_get ((p)) + #define mph_int_inc(p) do {g_atomic_int_inc ((p));} while (0) + #define mph_int_set(p,o,n) do { \ + while (!g_atomic_int_compare_and_exchange ((p), (o), (n))) {} \ + } while (0) +#else + #define mph_int_get(p) (*(p)) + #define mph_int_inc(p) do { (*(p))++; } while (0) + #define mph_int_set(p,o,n) do { *(p) = n; } while (0) +#endif + int Mono_Posix_Syscall_psignal (int sig, const char* s) { @@ -73,10 +90,10 @@ default_handler (int signum) for (i = 0; i < NUM_SIGNALS; ++i) { int fd; signal_info* h = &signals [i]; - if (g_atomic_int_get (&h->signum) != signum) + if (mph_int_get (&h->signum) != signum) continue; - g_atomic_int_inc (&h->count); - fd = g_atomic_int_get (&h->write_fd); + mph_int_inc (&h->count); + fd = mph_int_get (&h->write_fd); if (fd > 0) { char c = signum; write (fd, &c, 1); @@ -128,8 +145,8 @@ Mono_Unix_UnixSignal_install (int sig) } if (h) { - while (!g_atomic_int_compare_and_exchange (&h->count, h->count, 0)) {} - while (!g_atomic_int_compare_and_exchange (&h->signum, h->signum, sig)) {} + mph_int_set (&h->count, h->count, 0); + mph_int_set (&h->signum, h->signum, sig); } pthread_mutex_unlock (&signals_mutex); -- 2.25.1