diff options
| author | Philipp Stephani | 2018-01-17 23:28:46 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2018-01-18 20:14:36 +0100 |
| commit | 694ee38f8b7bd10f1d0eae8cb251daea70b5c820 (patch) | |
| tree | 53a4ebc808225e3c87bc8db48092e7f7ec8b7d92 /src | |
| parent | ebc1eea87b1309544ccb1a8a3ce53698cc2355d6 (diff) | |
| download | emacs-694ee38f8b7bd10f1d0eae8cb251daea70b5c820.tar.gz emacs-694ee38f8b7bd10f1d0eae8cb251daea70b5c820.zip | |
Fix module support if threads are disabled (Bug#30106)
* src/systhread.c (sys_thread_equal): New function.
* src/thread.c (in_current_thread): Move from emacs-module.c; use
sys_thread_equal.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs-module.c | 12 | ||||
| -rw-r--r-- | src/systhread.c | 18 | ||||
| -rw-r--r-- | src/systhread.h | 1 | ||||
| -rw-r--r-- | src/thread.c | 8 | ||||
| -rw-r--r-- | src/thread.h | 1 |
5 files changed, 28 insertions, 12 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index 4ee4014b4e1..3a85421e83a 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -805,18 +805,6 @@ module_function_arity (const struct Lisp_Module_Function *const function) | |||
| 805 | 805 | ||
| 806 | /* Helper functions. */ | 806 | /* Helper functions. */ |
| 807 | 807 | ||
| 808 | static bool | ||
| 809 | in_current_thread (void) | ||
| 810 | { | ||
| 811 | if (current_thread == NULL) | ||
| 812 | return false; | ||
| 813 | #ifdef HAVE_PTHREAD | ||
| 814 | return pthread_equal (pthread_self (), current_thread->thread_id); | ||
| 815 | #elif defined WINDOWSNT | ||
| 816 | return GetCurrentThreadId () == current_thread->thread_id; | ||
| 817 | #endif | ||
| 818 | } | ||
| 819 | |||
| 820 | static void | 808 | static void |
| 821 | module_assert_thread (void) | 809 | module_assert_thread (void) |
| 822 | { | 810 | { |
diff --git a/src/systhread.c b/src/systhread.c index 4ffb7db143a..3f162a2bcbf 100644 --- a/src/systhread.c +++ b/src/systhread.c | |||
| @@ -74,6 +74,12 @@ sys_thread_self (void) | |||
| 74 | return 0; | 74 | return 0; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | bool | ||
| 78 | sys_thread_equal (sys_thread_t t, sys_thread_t u) | ||
| 79 | { | ||
| 80 | return t == u; | ||
| 81 | } | ||
| 82 | |||
| 77 | int | 83 | int |
| 78 | sys_thread_create (sys_thread_t *t, const char *name, | 84 | sys_thread_create (sys_thread_t *t, const char *name, |
| 79 | thread_creation_function *func, void *datum) | 85 | thread_creation_function *func, void *datum) |
| @@ -155,6 +161,12 @@ sys_thread_self (void) | |||
| 155 | return pthread_self (); | 161 | return pthread_self (); |
| 156 | } | 162 | } |
| 157 | 163 | ||
| 164 | bool | ||
| 165 | sys_thread_equal (sys_thread_t t, sys_thread_t u) | ||
| 166 | { | ||
| 167 | return pthread_equal (t, u); | ||
| 168 | } | ||
| 169 | |||
| 158 | int | 170 | int |
| 159 | sys_thread_create (sys_thread_t *thread_ptr, const char *name, | 171 | sys_thread_create (sys_thread_t *thread_ptr, const char *name, |
| 160 | thread_creation_function *func, void *arg) | 172 | thread_creation_function *func, void *arg) |
| @@ -323,6 +335,12 @@ sys_thread_self (void) | |||
| 323 | return (sys_thread_t) GetCurrentThreadId (); | 335 | return (sys_thread_t) GetCurrentThreadId (); |
| 324 | } | 336 | } |
| 325 | 337 | ||
| 338 | bool | ||
| 339 | sys_thread_equal (sys_thread_t t, sys_thread_t u) | ||
| 340 | { | ||
| 341 | return t == u; | ||
| 342 | } | ||
| 343 | |||
| 326 | static thread_creation_function *thread_start_address; | 344 | static thread_creation_function *thread_start_address; |
| 327 | 345 | ||
| 328 | /* _beginthread wants a void function, while we are passed a function | 346 | /* _beginthread wants a void function, while we are passed a function |
diff --git a/src/systhread.h b/src/systhread.h index 4745d220654..5dbb12dffb6 100644 --- a/src/systhread.h +++ b/src/systhread.h | |||
| @@ -100,6 +100,7 @@ extern void sys_cond_broadcast (sys_cond_t *); | |||
| 100 | extern void sys_cond_destroy (sys_cond_t *); | 100 | extern void sys_cond_destroy (sys_cond_t *); |
| 101 | 101 | ||
| 102 | extern sys_thread_t sys_thread_self (void); | 102 | extern sys_thread_t sys_thread_self (void); |
| 103 | extern bool sys_thread_equal (sys_thread_t, sys_thread_t); | ||
| 103 | 104 | ||
| 104 | extern int sys_thread_create (sys_thread_t *, const char *, | 105 | extern int sys_thread_create (sys_thread_t *, const char *, |
| 105 | thread_creation_function *, | 106 | thread_creation_function *, |
diff --git a/src/thread.c b/src/thread.c index 60902b252b4..f11e3e5addb 100644 --- a/src/thread.c +++ b/src/thread.c | |||
| @@ -1022,6 +1022,14 @@ main_thread_p (void *ptr) | |||
| 1022 | return ptr == &main_thread; | 1022 | return ptr == &main_thread; |
| 1023 | } | 1023 | } |
| 1024 | 1024 | ||
| 1025 | bool | ||
| 1026 | in_current_thread (void) | ||
| 1027 | { | ||
| 1028 | if (current_thread == NULL) | ||
| 1029 | return false; | ||
| 1030 | return sys_thread_equal (sys_thread_self (), current_thread->thread_id); | ||
| 1031 | } | ||
| 1032 | |||
| 1025 | void | 1033 | void |
| 1026 | init_threads_once (void) | 1034 | init_threads_once (void) |
| 1027 | { | 1035 | { |
diff --git a/src/thread.h b/src/thread.h index 5746512b799..5ab5e90c70d 100644 --- a/src/thread.h +++ b/src/thread.h | |||
| @@ -303,6 +303,7 @@ extern void init_threads_once (void); | |||
| 303 | extern void init_threads (void); | 303 | extern void init_threads (void); |
| 304 | extern void syms_of_threads (void); | 304 | extern void syms_of_threads (void); |
| 305 | extern bool main_thread_p (void *); | 305 | extern bool main_thread_p (void *); |
| 306 | extern bool in_current_thread (void); | ||
| 306 | 307 | ||
| 307 | typedef int select_func (int, fd_set *, fd_set *, fd_set *, | 308 | typedef int select_func (int, fd_set *, fd_set *, fd_set *, |
| 308 | const struct timespec *, const sigset_t *); | 309 | const struct timespec *, const sigset_t *); |