diff options
| author | Paul Eggert | 2016-12-30 13:01:39 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-12-30 13:05:25 -0800 |
| commit | 966d51592f07ad9de6afebcd828e667cce0f6a27 (patch) | |
| tree | ae5ee7c99718abec1304682f43b620a1c00ddd06 /src | |
| parent | aef40049e3b81972703d3bde47b0961bcb08d7e1 (diff) | |
| download | emacs-966d51592f07ad9de6afebcd828e667cce0f6a27.tar.gz emacs-966d51592f07ad9de6afebcd828e667cce0f6a27.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs-module.c | 30 | ||||
| -rw-r--r-- | src/emacs.c | 6 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | src/sysdep.c | 14 | ||||
| -rw-r--r-- | src/syssignal.h | 1 |
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/>. */ | |||
| 28 | #include "lisp.h" | 28 | #include "lisp.h" |
| 29 | #include "dynlib.h" | 29 | #include "dynlib.h" |
| 30 | #include "coding.h" | 30 | #include "coding.h" |
| 31 | #include "syssignal.h" | ||
| 31 | 32 | ||
| 32 | #include <intprops.h> | 33 | #include <intprops.h> |
| 33 | #include <verify.h> | 34 | #include <verify.h> |
| @@ -41,15 +42,9 @@ enum { module_has_cleanup = true }; | |||
| 41 | enum { module_has_cleanup = false }; | 42 | enum { module_has_cleanup = false }; |
| 42 | #endif | 43 | #endif |
| 43 | 44 | ||
| 44 | /* Handle to the main thread. Used to verify that modules call us in | 45 | #ifdef WINDOWSNT |
| 45 | the right thread. */ | ||
| 46 | #ifdef HAVE_PTHREAD | ||
| 47 | # include <pthread.h> | ||
| 48 | static pthread_t main_thread; | ||
| 49 | #elif defined WINDOWSNT | ||
| 50 | #include <windows.h> | 46 | #include <windows.h> |
| 51 | #include "w32term.h" | 47 | #include "w32term.h" |
| 52 | static DWORD main_thread; | ||
| 53 | #endif | 48 | #endif |
| 54 | 49 | ||
| 55 | /* True if Lisp_Object and emacs_value have the same representation. | 50 | /* True if Lisp_Object and emacs_value have the same representation. |
| @@ -751,9 +746,9 @@ static void | |||
| 751 | check_main_thread (void) | 746 | check_main_thread (void) |
| 752 | { | 747 | { |
| 753 | #ifdef HAVE_PTHREAD | 748 | #ifdef HAVE_PTHREAD |
| 754 | eassert (pthread_equal (pthread_self (), main_thread)); | 749 | eassert (pthread_equal (pthread_self (), main_thread_id)); |
| 755 | #elif defined WINDOWSNT | 750 | #elif defined WINDOWSNT |
| 756 | eassert (GetCurrentThreadId () == main_thread); | 751 | eassert (GetCurrentThreadId () == dwMainThreadId); |
| 757 | #endif | 752 | #endif |
| 758 | } | 753 | } |
| 759 | 754 | ||
| @@ -1062,20 +1057,3 @@ syms_of_module (void) | |||
| 1062 | DEFSYM (Qinternal__module_call, "internal--module-call"); | 1057 | DEFSYM (Qinternal__module_call, "internal--module-call"); |
| 1063 | defsubr (&Sinternal_module_call); | 1058 | defsubr (&Sinternal_module_call); |
| 1064 | } | 1059 | } |
| 1065 | |||
| 1066 | /* Unlike syms_of_module, this initializer is called even from an | ||
| 1067 | initialized (dumped) Emacs. */ | ||
| 1068 | |||
| 1069 | void | ||
| 1070 | module_init (void) | ||
| 1071 | { | ||
| 1072 | /* It is not guaranteed that dynamic initializers run in the main thread, | ||
| 1073 | therefore detect the main thread here. */ | ||
| 1074 | #ifdef HAVE_PTHREAD | ||
| 1075 | main_thread = pthread_self (); | ||
| 1076 | #elif defined WINDOWSNT | ||
| 1077 | /* The 'main' function already recorded the main thread's thread ID, | ||
| 1078 | so we need just to use it . */ | ||
| 1079 | main_thread = dwMainThreadId; | ||
| 1080 | #endif | ||
| 1081 | } | ||
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) | |||
| 738 | non-ASCII file names during startup. */ | 738 | non-ASCII file names during startup. */ |
| 739 | w32_init_file_name_codepage (); | 739 | w32_init_file_name_codepage (); |
| 740 | #endif | 740 | #endif |
| 741 | /* This has to be done before module_init is called below, so that | ||
| 742 | the latter could use the thread ID of the main thread. */ | ||
| 743 | w32_init_main_thread (); | 741 | w32_init_main_thread (); |
| 744 | #endif | 742 | #endif |
| 745 | 743 | ||
| @@ -757,10 +755,6 @@ main (int argc, char **argv) | |||
| 757 | init_standard_fds (); | 755 | init_standard_fds (); |
| 758 | atexit (close_output_streams); | 756 | atexit (close_output_streams); |
| 759 | 757 | ||
| 760 | #ifdef HAVE_MODULES | ||
| 761 | module_init (); | ||
| 762 | #endif | ||
| 763 | |||
| 764 | sort_args (argc, argv); | 758 | sort_args (argc, argv); |
| 765 | argc = 0; | 759 | argc = 0; |
| 766 | while (argv[argc]) argc++; | 760 | 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); | |||
| 3880 | extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p); | 3880 | extern Lisp_Object make_user_ptr (void (*finalizer) (void *), void *p); |
| 3881 | 3881 | ||
| 3882 | /* Defined in emacs-module.c. */ | 3882 | /* Defined in emacs-module.c. */ |
| 3883 | extern void module_init (void); | ||
| 3884 | extern void syms_of_module (void); | 3883 | extern void syms_of_module (void); |
| 3885 | #endif | 3884 | #endif |
| 3886 | 3885 | ||
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) | |||
| 1612 | } | 1612 | } |
| 1613 | 1613 | ||
| 1614 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD | 1614 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD |
| 1615 | static pthread_t main_thread; | 1615 | pthread_t main_thread_id; |
| 1616 | #endif | 1616 | #endif |
| 1617 | 1617 | ||
| 1618 | /* SIG has arrived at the current process. Deliver it to the main | 1618 | /* 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) | |||
| 1636 | 1636 | ||
| 1637 | bool on_main_thread = true; | 1637 | bool on_main_thread = true; |
| 1638 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD | 1638 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD |
| 1639 | if (! pthread_equal (pthread_self (), main_thread)) | 1639 | if (! pthread_equal (pthread_self (), main_thread_id)) |
| 1640 | { | 1640 | { |
| 1641 | sigset_t blocked; | 1641 | sigset_t blocked; |
| 1642 | sigemptyset (&blocked); | 1642 | sigemptyset (&blocked); |
| 1643 | sigaddset (&blocked, sig); | 1643 | sigaddset (&blocked, sig); |
| 1644 | pthread_sigmask (SIG_BLOCK, &blocked, 0); | 1644 | pthread_sigmask (SIG_BLOCK, &blocked, 0); |
| 1645 | pthread_kill (main_thread, sig); | 1645 | pthread_kill (main_thread_id, sig); |
| 1646 | on_main_thread = false; | 1646 | on_main_thread = false; |
| 1647 | } | 1647 | } |
| 1648 | #endif | 1648 | #endif |
| @@ -1668,12 +1668,12 @@ deliver_thread_signal (int sig, signal_handler_t handler) | |||
| 1668 | int old_errno = errno; | 1668 | int old_errno = errno; |
| 1669 | 1669 | ||
| 1670 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD | 1670 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD |
| 1671 | if (! pthread_equal (pthread_self (), main_thread)) | 1671 | if (! pthread_equal (pthread_self (), main_thread_id)) |
| 1672 | { | 1672 | { |
| 1673 | thread_backtrace_npointers | 1673 | thread_backtrace_npointers |
| 1674 | = backtrace (thread_backtrace_buffer, BACKTRACE_LIMIT_MAX); | 1674 | = backtrace (thread_backtrace_buffer, BACKTRACE_LIMIT_MAX); |
| 1675 | sigaction (sig, &process_fatal_action, 0); | 1675 | sigaction (sig, &process_fatal_action, 0); |
| 1676 | pthread_kill (main_thread, sig); | 1676 | pthread_kill (main_thread_id, sig); |
| 1677 | 1677 | ||
| 1678 | /* Avoid further damage while the main thread is exiting. */ | 1678 | /* Avoid further damage while the main thread is exiting. */ |
| 1679 | while (1) | 1679 | while (1) |
| @@ -1796,7 +1796,7 @@ handle_sigsegv (int sig, siginfo_t *siginfo, void *arg) | |||
| 1796 | bool fatal = gc_in_progress; | 1796 | bool fatal = gc_in_progress; |
| 1797 | 1797 | ||
| 1798 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD | 1798 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD |
| 1799 | if (!fatal && !pthread_equal (pthread_self (), main_thread)) | 1799 | if (!fatal && !pthread_equal (pthread_self (), main_thread_id)) |
| 1800 | fatal = true; | 1800 | fatal = true; |
| 1801 | #endif | 1801 | #endif |
| 1802 | 1802 | ||
| @@ -1888,7 +1888,7 @@ init_signals (bool dumping) | |||
| 1888 | sigemptyset (&empty_mask); | 1888 | sigemptyset (&empty_mask); |
| 1889 | 1889 | ||
| 1890 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD | 1890 | #ifdef FORWARD_SIGNAL_TO_MAIN_THREAD |
| 1891 | main_thread = pthread_self (); | 1891 | main_thread_id = pthread_self (); |
| 1892 | #endif | 1892 | #endif |
| 1893 | 1893 | ||
| 1894 | #if !HAVE_DECL_SYS_SIGLIST && !defined _sys_siglist | 1894 | #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 *); | |||
| 32 | 32 | ||
| 33 | #ifdef HAVE_PTHREAD | 33 | #ifdef HAVE_PTHREAD |
| 34 | #include <pthread.h> | 34 | #include <pthread.h> |
| 35 | extern pthread_t main_thread_id; | ||
| 35 | /* If defined, asynchronous signals delivered to a non-main thread are | 36 | /* If defined, asynchronous signals delivered to a non-main thread are |
| 36 | forwarded to the main thread. */ | 37 | forwarded to the main thread. */ |
| 37 | #define FORWARD_SIGNAL_TO_MAIN_THREAD | 38 | #define FORWARD_SIGNAL_TO_MAIN_THREAD |