#include "lisp.h"
#include "dynlib.h"
#include "coding.h"
+#include "syssignal.h"
#include <intprops.h>
#include <verify.h>
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.
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
}
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
-}
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
init_standard_fds ();
atexit (close_output_streams);
-#ifdef HAVE_MODULES
- module_init ();
-#endif
-
sort_args (argc, argv);
argc = 0;
while (argv[argc]) argc++;
}
#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
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
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)
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
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