summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/emacs-module.c30
-rw-r--r--src/emacs.c6
-rw-r--r--src/lisp.h1
-rw-r--r--src/sysdep.c14
-rw-r--r--src/syssignal.h1
5 files changed, 12 insertions, 40 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c
index 68aeb0ce704..280c0550c9b 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -28,6 +28,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "lisp.h"
#include "dynlib.h"
#include "coding.h"
+#include "syssignal.h"
#include <intprops.h>
#include <verify.h>
@@ -41,15 +42,9 @@ enum { module_has_cleanup = true };
enum { module_has_cleanup = false };
#endif
-/* Handle to the main thread. Used to verify that modules call us in
- the right thread. */
-#ifdef HAVE_PTHREAD
-# include <pthread.h>
-static pthread_t main_thread;
-#elif defined WINDOWSNT
+#ifdef WINDOWSNT
#include <windows.h>
#include "w32term.h"
-static DWORD main_thread;
#endif
/* True if Lisp_Object and emacs_value have the same representation.
@@ -751,9 +746,9 @@ static void
check_main_thread (void)
{
#ifdef HAVE_PTHREAD
- eassert (pthread_equal (pthread_self (), main_thread));
+ eassert (pthread_equal (pthread_self (), main_thread_id));
#elif defined WINDOWSNT
- eassert (GetCurrentThreadId () == main_thread);
+ eassert (GetCurrentThreadId () == dwMainThreadId);
#endif
}
@@ -1062,20 +1057,3 @@ syms_of_module (void)
DEFSYM (Qinternal__module_call, "internal--module-call");
defsubr (&Sinternal_module_call);
}
-
-/* Unlike syms_of_module, this initializer is called even from an
- initialized (dumped) Emacs. */
-
-void
-module_init (void)
-{
- /* It is not guaranteed that dynamic initializers run in the main thread,
- therefore detect the main thread here. */
-#ifdef HAVE_PTHREAD
- main_thread = pthread_self ();
-#elif defined WINDOWSNT
- /* The 'main' function already recorded the main thread's thread ID,
- so we need just to use it . */
- main_thread = dwMainThreadId;
-#endif
-}
diff --git a/src/emacs.c b/src/emacs.c
index eff3f9dcb87..d461fe241c0 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -738,8 +738,6 @@ main (int argc, char **argv)
non-ASCII file names during startup. */
w32_init_file_name_codepage ();
#endif
- /* This has to be done before module_init is called below, so that
- the latter could use the thread ID of the main thread. */
w32_init_main_thread ();
#endif
@@ -757,10 +755,6 @@ main (int argc, char **argv)
init_standard_fds ();
atexit (close_output_streams);
-#ifdef HAVE_MODULES
- module_init ();
-#endif
-
sort_args (argc, argv);
argc = 0;
while (argv[argc]) argc++;
diff --git a/src/lisp.h b/src/lisp.h
index 1a586cab0d0..84963086216 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3880,7 +3880,6 @@ extern bool let_shadows_global_binding_p (Lisp_Object symbol);
extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p);
/* Defined in emacs-module.c. */
-extern void module_init (void);
extern void syms_of_module (void);
#endif
diff --git a/src/sysdep.c b/src/sysdep.c
index 1ba336e387a..1227afc8db7 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1612,7 +1612,7 @@ emacs_sigaction_init (struct sigaction *action, signal_handler_t handler)
}
#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
-static pthread_t main_thread;
+pthread_t main_thread_id;
#endif
/* SIG has arrived at the current process. Deliver it to the main
@@ -1636,13 +1636,13 @@ deliver_process_signal (int sig, signal_handler_t handler)
bool on_main_thread = true;
#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
- if (! pthread_equal (pthread_self (), main_thread))
+ if (! pthread_equal (pthread_self (), main_thread_id))
{
sigset_t blocked;
sigemptyset (&blocked);
sigaddset (&blocked, sig);
pthread_sigmask (SIG_BLOCK, &blocked, 0);
- pthread_kill (main_thread, sig);
+ pthread_kill (main_thread_id, sig);
on_main_thread = false;
}
#endif
@@ -1668,12 +1668,12 @@ deliver_thread_signal (int sig, signal_handler_t handler)
int old_errno = errno;
#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
- if (! pthread_equal (pthread_self (), main_thread))
+ if (! pthread_equal (pthread_self (), main_thread_id))
{
thread_backtrace_npointers
= backtrace (thread_backtrace_buffer, BACKTRACE_LIMIT_MAX);
sigaction (sig, &process_fatal_action, 0);
- pthread_kill (main_thread, sig);
+ pthread_kill (main_thread_id, sig);
/* Avoid further damage while the main thread is exiting. */
while (1)
@@ -1796,7 +1796,7 @@ handle_sigsegv (int sig, siginfo_t *siginfo, void *arg)
bool fatal = gc_in_progress;
#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
- if (!fatal && !pthread_equal (pthread_self (), main_thread))
+ if (!fatal && !pthread_equal (pthread_self (), main_thread_id))
fatal = true;
#endif
@@ -1888,7 +1888,7 @@ init_signals (bool dumping)
sigemptyset (&empty_mask);
#ifdef FORWARD_SIGNAL_TO_MAIN_THREAD
- main_thread = pthread_self ();
+ main_thread_id = pthread_self ();
#endif
#if !HAVE_DECL_SYS_SIGLIST && !defined _sys_siglist
diff --git a/src/syssignal.h b/src/syssignal.h
index 62704fc351e..215aafe314b 100644
--- a/src/syssignal.h
+++ b/src/syssignal.h
@@ -32,6 +32,7 @@ extern void unblock_tty_out_signal (sigset_t const *);
#ifdef HAVE_PTHREAD
#include <pthread.h>
+extern pthread_t main_thread_id;
/* If defined, asynchronous signals delivered to a non-main thread are
forwarded to the main thread. */
#define FORWARD_SIGNAL_TO_MAIN_THREAD