diff options
| author | Paul Eggert | 2018-10-19 09:06:52 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-10-19 09:26:50 -0700 |
| commit | d2a07b9a82a632e8baa179c667a98d275e5f6973 (patch) | |
| tree | aa9ba321dc84936722b5345f67bf089678840bc6 /src/thread.c | |
| parent | fc3f93705543408b868feb7b93b8d77ab1c6ae53 (diff) | |
| download | emacs-d2a07b9a82a632e8baa179c667a98d275e5f6973.tar.gz emacs-d2a07b9a82a632e8baa179c667a98d275e5f6973.zip | |
Fix struct thread alignment on FreeBSD x86
Problem reported by Joseph Mingrone in:
https://lists.gnu.org/r/emacs-devel/2018-10/msg00238.html
While we’re at it, apply a similar fix to struct Lisp_Subr; this
removes the need for GCALIGNED_STRUCT_MEMBER and thus can shrink
struct Lisp_Subr a bit.
* configure.ac (HAVE_STRUCT_ATTRIBUTE_ALIGNED): Bring back this macro.
Although used only for performance (not to actually align
structures), we might as well take advantage of it.
* src/lisp.h (GCALIGNED_STRUCT_MEMBER): Remove; all uses removed.
(union Aligned_Lisp_Subr): New type, like struct Lisp_Subr but aligned.
* src/lisp.h (XSUBR, DEFUN):
* src/lread.c (defsubr): Use it. All callers changed.
* src/thread.c (union aligned_thread_state): New type.
(main_thread): Now of this type, so it’s aligned.
All uses changed.
* src/xmenu.c (syms_of_xmenu) [USE_GTK || USE_X_TOOLKIT]:
Adjust to union Aligned_Lisp_Subr change.
Diffstat (limited to 'src/thread.c')
| -rw-r--r-- | src/thread.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/src/thread.c b/src/thread.c index 3674af0e47b..6612697b95e 100644 --- a/src/thread.c +++ b/src/thread.c | |||
| @@ -27,11 +27,18 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 27 | #include "syssignal.h" | 27 | #include "syssignal.h" |
| 28 | #include "keyboard.h" | 28 | #include "keyboard.h" |
| 29 | 29 | ||
| 30 | static struct thread_state main_thread; | 30 | union aligned_thread_state |
| 31 | { | ||
| 32 | struct thread_state s; | ||
| 33 | GCALIGNED_UNION_MEMBER | ||
| 34 | }; | ||
| 35 | verify (GCALIGNED (union aligned_thread_state)); | ||
| 36 | |||
| 37 | static union aligned_thread_state main_thread; | ||
| 31 | 38 | ||
| 32 | struct thread_state *current_thread = &main_thread; | 39 | struct thread_state *current_thread = &main_thread.s; |
| 33 | 40 | ||
| 34 | static struct thread_state *all_threads = &main_thread; | 41 | static struct thread_state *all_threads = &main_thread.s; |
| 35 | 42 | ||
| 36 | static sys_mutex_t global_lock; | 43 | static sys_mutex_t global_lock; |
| 37 | 44 | ||
| @@ -113,7 +120,7 @@ maybe_reacquire_global_lock (void) | |||
| 113 | /* SIGINT handler is always run on the main thread, see | 120 | /* SIGINT handler is always run on the main thread, see |
| 114 | deliver_process_signal, so reflect that in our thread-tracking | 121 | deliver_process_signal, so reflect that in our thread-tracking |
| 115 | variables. */ | 122 | variables. */ |
| 116 | current_thread = &main_thread; | 123 | current_thread = &main_thread.s; |
| 117 | 124 | ||
| 118 | if (current_thread->not_holding_lock) | 125 | if (current_thread->not_holding_lock) |
| 119 | { | 126 | { |
| @@ -659,7 +666,7 @@ mark_threads (void) | |||
| 659 | void | 666 | void |
| 660 | unmark_main_thread (void) | 667 | unmark_main_thread (void) |
| 661 | { | 668 | { |
| 662 | main_thread.header.size &= ~ARRAY_MARK_FLAG; | 669 | main_thread.s.header.size &= ~ARRAY_MARK_FLAG; |
| 663 | } | 670 | } |
| 664 | 671 | ||
| 665 | 672 | ||
| @@ -1043,23 +1050,23 @@ thread_check_current_buffer (struct buffer *buffer) | |||
| 1043 | static void | 1050 | static void |
| 1044 | init_main_thread (void) | 1051 | init_main_thread (void) |
| 1045 | { | 1052 | { |
| 1046 | main_thread.header.size | 1053 | main_thread.s.header.size |
| 1047 | = PSEUDOVECSIZE (struct thread_state, m_stack_bottom); | 1054 | = PSEUDOVECSIZE (struct thread_state, m_stack_bottom); |
| 1048 | XSETPVECTYPE (&main_thread, PVEC_THREAD); | 1055 | XSETPVECTYPE (&main_thread.s, PVEC_THREAD); |
| 1049 | main_thread.m_last_thing_searched = Qnil; | 1056 | main_thread.s.m_last_thing_searched = Qnil; |
| 1050 | main_thread.m_saved_last_thing_searched = Qnil; | 1057 | main_thread.s.m_saved_last_thing_searched = Qnil; |
| 1051 | main_thread.name = Qnil; | 1058 | main_thread.s.name = Qnil; |
| 1052 | main_thread.function = Qnil; | 1059 | main_thread.s.function = Qnil; |
| 1053 | main_thread.result = Qnil; | 1060 | main_thread.s.result = Qnil; |
| 1054 | main_thread.error_symbol = Qnil; | 1061 | main_thread.s.error_symbol = Qnil; |
| 1055 | main_thread.error_data = Qnil; | 1062 | main_thread.s.error_data = Qnil; |
| 1056 | main_thread.event_object = Qnil; | 1063 | main_thread.s.event_object = Qnil; |
| 1057 | } | 1064 | } |
| 1058 | 1065 | ||
| 1059 | bool | 1066 | bool |
| 1060 | main_thread_p (void *ptr) | 1067 | main_thread_p (void *ptr) |
| 1061 | { | 1068 | { |
| 1062 | return ptr == &main_thread; | 1069 | return ptr == &main_thread.s; |
| 1063 | } | 1070 | } |
| 1064 | 1071 | ||
| 1065 | bool | 1072 | bool |
| @@ -1080,11 +1087,11 @@ void | |||
| 1080 | init_threads (void) | 1087 | init_threads (void) |
| 1081 | { | 1088 | { |
| 1082 | init_main_thread (); | 1089 | init_main_thread (); |
| 1083 | sys_cond_init (&main_thread.thread_condvar); | 1090 | sys_cond_init (&main_thread.s.thread_condvar); |
| 1084 | sys_mutex_init (&global_lock); | 1091 | sys_mutex_init (&global_lock); |
| 1085 | sys_mutex_lock (&global_lock); | 1092 | sys_mutex_lock (&global_lock); |
| 1086 | current_thread = &main_thread; | 1093 | current_thread = &main_thread.s; |
| 1087 | main_thread.thread_id = sys_thread_self (); | 1094 | main_thread.s.thread_id = sys_thread_self (); |
| 1088 | } | 1095 | } |
| 1089 | 1096 | ||
| 1090 | void | 1097 | void |
| @@ -1130,7 +1137,7 @@ syms_of_threads (void) | |||
| 1130 | DEFVAR_LISP ("main-thread", Vmain_thread, | 1137 | DEFVAR_LISP ("main-thread", Vmain_thread, |
| 1131 | doc: /* The main thread of Emacs. */); | 1138 | doc: /* The main thread of Emacs. */); |
| 1132 | #ifdef THREADS_ENABLED | 1139 | #ifdef THREADS_ENABLED |
| 1133 | XSETTHREAD (Vmain_thread, &main_thread); | 1140 | XSETTHREAD (Vmain_thread, &main_thread.s); |
| 1134 | #else | 1141 | #else |
| 1135 | Vmain_thread = Qnil; | 1142 | Vmain_thread = Qnil; |
| 1136 | #endif | 1143 | #endif |