Author: jonpryor
Date: 2008-02-07 09:11:38 -0500 (Thu, 07 Feb 2008)
New Revision: 95140

Modified:
   trunk/mono/support/ChangeLog
   trunk/mono/support/signal.c
Log:
        * signal.c: Make the signal handler thread-safe, so that it can safely 
be
          invoked concurrently from multiple threads.


Modified: trunk/mono/support/ChangeLog
===================================================================
--- trunk/mono/support/ChangeLog        2008-02-07 13:41:27 UTC (rev 95139)
+++ trunk/mono/support/ChangeLog        2008-02-07 14:11:38 UTC (rev 95140)
@@ -1,3 +1,8 @@
+2008-02-07  Jonathan Pryor  <[EMAIL PROTECTED]>
+
+       * signal.c: Make the signal handler thread-safe, so that it can safely 
be
+         invoked concurrently from multiple threads.
+
 2008-02-05  Jonathan Pryor  <[EMAIL PROTECTED]>
 
        * signal.c: Fix the Win32 build.

Modified: trunk/mono/support/signal.c
===================================================================
--- trunk/mono/support/signal.c 2008-02-07 13:41:27 UTC (rev 95139)
+++ trunk/mono/support/signal.c 2008-02-07 14:11:38 UTC (rev 95140)
@@ -71,13 +71,15 @@
 {
        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 @@
                                break;
                        }
                        else {
-                               h->signum       = sig;
-                               h->count        = 0;
                                h->have_handler = 1;
                        }
                }
@@ -127,6 +127,11 @@
                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;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to