diff src/syssignal.h @ 58986:59945307b86b

* syssignal.h: Declare main_thread. (SIGNAL_THREAD_CHECK): New macro. * keyboard.c (input_available_signal): Move thread checking code to macro SIGNAL_THREAD_CHECK and call that macro. (interrupt_signal): Call SIGNAL_THREAD_CHECK. * alloc.c (uninterrupt_malloc): Move main_thread to emacs.c. * emacs.c: Define main_thread. (main): Initialize main_thread. (handle_USR1_signal, handle_USR2_signal, fatal_error_signal) (memory_warning_signal): Call SIGNAL_THREAD_CHECK. * floatfns.c (float_error): Call SIGNAL_THREAD_CHECK. * dispnew.c (window_change_signal): Call SIGNAL_THREAD_CHECK. * sysdep.c (select_alarm): Call SIGNAL_THREAD_CHECK. * process.c (send_process_trap, sigchld_handler): Call SIGNAL_THREAD_CHECK. * data.c (arith_error): Call SIGNAL_THREAD_CHECK. * atimer.c (alarm_signal_handler): Call SIGNAL_THREAD_CHECK.
author Jan Djärv <jan.h.d@swipnet.se>
date Wed, 15 Dec 2004 21:40:41 +0000
parents c208f88ccc56
children a8fa7c632ee4 4ee39d9428b0 eac554634bfa
line wrap: on
line diff
--- a/src/syssignal.h	Wed Dec 15 21:34:14 2004 +0000
+++ b/src/syssignal.h	Wed Dec 15 21:40:41 2004 +0000
@@ -20,6 +20,11 @@
 
 extern void init_signals P_ ((void));
 
+#ifdef HAVE_GTK_AND_PTHREAD
+#include <pthread.h>
+extern pthread_t main_thread;
+#endif
+
 #ifdef POSIX_SIGNALS
 
 /* Don't #include <signal.h>.  That header should always be #included
@@ -198,5 +203,27 @@
 char *strsignal ();
 #endif
 
+#ifdef HAVE_GTK_AND_PTHREAD
+#define SIGNAL_THREAD_CHECK(signo)                                      \
+  do {                                                                  \
+    if (pthread_self () != main_thread)                                 \
+      {                                                                 \
+        /* POSIX says any thread can receive the signal.  On GNU/Linux  \
+           that is not true, but for other systems (FreeBSD at least)   \
+           it is.  So direct the signal to the correct thread and block \
+           it from this thread.  */                                     \
+        sigset_t new_mask;                                              \
+                                                                        \
+        sigemptyset (&new_mask);                                        \
+        sigaddset (&new_mask, signo);                                   \
+        pthread_sigmask (SIG_BLOCK, &new_mask, 0);                      \
+        pthread_kill (main_thread, signo);                              \
+        return;                                                         \
+      }                                                                 \
+   } while (0)
+
+#else /* not HAVE_GTK_AND_PTHREAD */
+#define SIGNAL_THREAD_CHECK(signo)
+#endif /* not HAVE_GTK_AND_PTHREAD */
 /* arch-tag: 4580e86a-340d-4574-9e11-a742b6e1a152
    (do not change this comment) */