diff options
author | Jonathan Pryor <jpryor@novell.com> | 2008-02-07 17:11:38 +0300 |
---|---|---|
committer | Jonathan Pryor <jpryor@novell.com> | 2008-02-07 17:11:38 +0300 |
commit | 11b3c493f4c3050570852ebb5dd5f71e7fb2e960 (patch) | |
tree | 029e1742d1227d1f49e1830b8496330da68ffa8f /support | |
parent | 6b06beb2874a95d5eed9fce172c9c60683e0acf3 (diff) |
* signal.c: Make the signal handler thread-safe, so that it can safely be
invoked concurrently from multiple threads.
svn path=/trunk/mono/; revision=95140
Diffstat (limited to 'support')
-rw-r--r-- | support/ChangeLog | 5 | ||||
-rw-r--r-- | support/signal.c | 17 |
2 files changed, 16 insertions, 6 deletions
diff --git a/support/ChangeLog b/support/ChangeLog index 4e9419b6f4d..0d17de5bca8 100644 --- a/support/ChangeLog +++ b/support/ChangeLog @@ -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. diff --git a/support/signal.c b/support/signal.c index fd95bb14db8..d995fa970d3 100644 --- a/support/signal.c +++ b/support/signal.c @@ -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; |