Rename main_thread to main_thread_id and simplify
* src/emacs-module.c: Include syssignal.h, for main_thread_id. [HAVE_PTHREAD]: Do not include pthread.h. (main_thread): Remove. All uses replaced by main_thread_id, or by dwMainThreadId on NT. Since the HAVE_PTHREAD code is now using the main_thread_id established by sysdep.c, there is no need for a separate copy of the main thread ID here. (module_init): Remove. All uses removed. * src/sysdep.c (main_thread_id) [HAVE_PTHREAD]: Rename from main_thread. All uses changed. Now extern.
This commit is contained in:
parent
aef40049e3
commit
966d51592f
5 changed files with 12 additions and 40 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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++;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
14
src/sysdep.c
14
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue