From: Philipp Stephani
Date: Wed, 17 Jan 2018 22:28:46 +0000 (+0100)
Subject: Fix module support if threads are disabled (Bug#30106)
X-Git-Tag: emacs-27.0.90~5860
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=694ee38f8b7bd10f1d0eae8cb251daea70b5c820;p=emacs.git
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.
---
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)
/* Helper functions. */
-static bool
-in_current_thread (void)
-{
- if (current_thread == NULL)
- return false;
-#ifdef HAVE_PTHREAD
- return pthread_equal (pthread_self (), current_thread->thread_id);
-#elif defined WINDOWSNT
- return GetCurrentThreadId () == current_thread->thread_id;
-#endif
-}
-
static void
module_assert_thread (void)
{
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)
return 0;
}
+bool
+sys_thread_equal (sys_thread_t t, sys_thread_t u)
+{
+ return t == u;
+}
+
int
sys_thread_create (sys_thread_t *t, const char *name,
thread_creation_function *func, void *datum)
@@ -155,6 +161,12 @@ sys_thread_self (void)
return pthread_self ();
}
+bool
+sys_thread_equal (sys_thread_t t, sys_thread_t u)
+{
+ return pthread_equal (t, u);
+}
+
int
sys_thread_create (sys_thread_t *thread_ptr, const char *name,
thread_creation_function *func, void *arg)
@@ -323,6 +335,12 @@ sys_thread_self (void)
return (sys_thread_t) GetCurrentThreadId ();
}
+bool
+sys_thread_equal (sys_thread_t t, sys_thread_t u)
+{
+ return t == u;
+}
+
static thread_creation_function *thread_start_address;
/* _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 *);
extern void sys_cond_destroy (sys_cond_t *);
extern sys_thread_t sys_thread_self (void);
+extern bool sys_thread_equal (sys_thread_t, sys_thread_t);
extern int sys_thread_create (sys_thread_t *, const char *,
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)
return ptr == &main_thread;
}
+bool
+in_current_thread (void)
+{
+ if (current_thread == NULL)
+ return false;
+ return sys_thread_equal (sys_thread_self (), current_thread->thread_id);
+}
+
void
init_threads_once (void)
{
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);
extern void init_threads (void);
extern void syms_of_threads (void);
extern bool main_thread_p (void *);
+extern bool in_current_thread (void);
typedef int select_func (int, fd_set *, fd_set *, fd_set *,
const struct timespec *, const sigset_t *);