Subject: bug#30106: [PATCH 2/2] Fix module support if threads are disabled (Bug#30106)

From: Philipp Stephani <[email-masked]>
Date: Wed, 17 Jan 2018 23:28:46 +0100

* src/systhread.c (sys_thread_equal): New function.
* src/emacs-module.c (in_current_thread): Use it.
---
 src/emacs-module.c |  7 ++-----
 src/systhread.c    | 18 ++++++++++++++++++
 src/systhread.h    |  1 +
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/emacs-module.c b/src/emacs-module.c
index 00f0e86d7d..298080e646 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -31,6 +31,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 #include "coding.h"
 #include "keyboard.h"
 #include "syssignal.h"
+#include "systhread.h"
 #include "thread.h"
 
 #include <intprops.h>
@@ -805,11 +806,7 @@ 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
+  return sys_thread_equal (sys_thread_self (), current_thread->thread_id);
 }
 
 static void
diff --git a/src/systhread.c b/src/systhread.c
index 4ffb7db143..3f162a2bcb 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 4745d22065..5dbb12dffb 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 *,
-- 
2.15.1