From ffe46baecaae232c41b41ce2d3ecbb81fb71c9e5 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 17 Sep 2009 11:40:18 +0200 Subject: [PATCH] Signals can be captured by any thread. --- src/syssignal.h | 2 +- src/thread.c | 19 +++++++++++++++++++ src/thread.h | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/syssignal.h b/src/syssignal.h index f435d338594..cab36900017 100644 --- a/src/syssignal.h +++ b/src/syssignal.h @@ -180,7 +180,7 @@ char *strsignal (); #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD #define SIGNAL_THREAD_CHECK(signo) \ do { \ - if (!pthread_equal (pthread_self (), main_thread)) \ + if (!user_thread_p ()) \ { \ /* POSIX says any thread can receive the signal. On GNU/Linux \ that is not true, but for other systems (FreeBSD at least) \ diff --git a/src/thread.c b/src/thread.c index 36f075dc646..2bcea5c54a5 100644 --- a/src/thread.c +++ b/src/thread.c @@ -162,6 +162,7 @@ run_thread (void *state) self->m_specpdl = xmalloc (self->m_specpdl_size * sizeof (struct specbinding)); self->m_specpdl_ptr = self->m_specpdl; + self->pthread_id = pthread_self (); /* Thread-local assignment. */ current_thread = self; @@ -262,6 +263,23 @@ get_main_thread (void) return result; } +/* Is the current an user thread. */ +int +user_thread_p (void) +{ + struct thread_state *it = all_threads; + pthread_t self = pthread_self (); + do + { + if (it->pthread_id == self) + return 1; + } + while (it = it->next_thread); + + return 0; +} + + int other_threads_p (void) { @@ -273,6 +291,7 @@ init_threads (void) { pthread_mutex_init (&global_lock, NULL); pthread_mutex_lock (&global_lock); + primary_thread.pthread_id = pthread_self (); } void diff --git a/src/thread.h b/src/thread.h index 8f7b02ba2da..69e801f9a3f 100644 --- a/src/thread.h +++ b/src/thread.h @@ -69,6 +69,8 @@ struct thread_state #define current_buffer (current_thread->m_current_buffer) struct thread_state *next_thread; + + pthread_t pthread_id; }; extern __thread struct thread_state *current_thread; @@ -86,3 +88,5 @@ extern Lisp_Object get_main_thread P_ ((void)); extern pthread_mutex_t global_lock; extern int other_threads_p P_ ((void)); + +extern int user_thread_p P_ ((void)); -- 2.11.4.GIT