* signal.c: Make the signal handler thread-safe, so that it can safely be
authorJonathan Pryor <jpryor@novell.com>
Thu, 7 Feb 2008 14:11:38 +0000 (14:11 -0000)
committerJonathan Pryor <jpryor@novell.com>
Thu, 7 Feb 2008 14:11:38 +0000 (14:11 -0000)
  invoked concurrently from multiple threads.

svn path=/trunk/mono/; revision=95140

support/ChangeLog
support/signal.c

index 4e9419b6f4ddb73cb5916610ab774e678938ffd6..0d17de5bca8308f8cf23b9fa4b2e42fc38af53a9 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-07  Jonathan Pryor  <jpryor@novell.com>
+
+       * signal.c: Make the signal handler thread-safe, so that it can safely be
+         invoked concurrently from multiple threads.
+
 2008-02-05  Jonathan Pryor  <jpryor@novell.com>
 
        * signal.c: Fix the Win32 build.
index fd95bb14db85b9d64514a069c10ba47d1856f7bf..d995fa970d318612b800ca76430ee0aa767f8b8b 100644 (file)
@@ -71,13 +71,15 @@ default_handler (int signum)
 {
        int i;
        for (i = 0; i < NUM_SIGNALS; ++i) {
+               int fd;
                signal_info* h = &signals [i];
-               if (h->signum != signum)
+               if (g_atomic_int_get (&h->signum) != signum)
                        continue;
-               ++h->count;
-               if (h->write_fd > 0) {
+               g_atomic_int_inc (&h->count);
+               fd = g_atomic_int_get (&h->write_fd);
+               if (fd > 0) {
                        char c = signum;
-                       write (h->write_fd, &c, 1);
+                       write (fd, &c, 1);
                }
        }
 }
@@ -108,8 +110,6 @@ Mono_Unix_UnixSignal_install (int sig)
                                break;
                        }
                        else {
-                               h->signum       = sig;
-                               h->count        = 0;
                                h->have_handler = 1;
                        }
                }
@@ -127,6 +127,11 @@ Mono_Unix_UnixSignal_install (int sig)
                h->handler      = handler;
        }
 
+       if (h) {
+               g_atomic_int_set (&h->count, 0);
+               g_atomic_int_set (&h->signum, sig);
+       }
+
        pthread_mutex_unlock (&signals_mutex);
 
        return h;