From 8590d61ea9b6b91c89a14a8d0f6829c8a3a8c6c8 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 28 Oct 2021 15:51:40 +0900 Subject: [PATCH] Select including thread impl file at config time --- thread.c | 6 ++---- tool/m4/ruby_thread.m4 | 9 +++++++++ vm_core.h | 6 +----- win32/Makefile.sub | 4 ++++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/thread.c b/thread.c index 1209de948adde6..0e3b53ae0b6264 100644 --- a/thread.c +++ b/thread.c @@ -349,8 +349,9 @@ ubf_sigwait(void *ignore) rb_thread_wakeup_timer_thread(0); } +#include THREAD_IMPL_SRC + #if defined(_WIN32) -#include "thread_win32.c" #define DEBUG_OUT() \ WaitForSingleObject(&debug_mutex, INFINITE); \ @@ -359,7 +360,6 @@ ubf_sigwait(void *ignore) ReleaseMutex(&debug_mutex); #elif defined(HAVE_PTHREAD_H) -#include "thread_pthread.c" #define DEBUG_OUT() \ pthread_mutex_lock(&debug_mutex); \ @@ -368,8 +368,6 @@ ubf_sigwait(void *ignore) fflush(stdout); \ pthread_mutex_unlock(&debug_mutex); -#else -#error "unsupported thread type" #endif /* diff --git a/tool/m4/ruby_thread.m4 b/tool/m4/ruby_thread.m4 index 92d80421f14fc6..6f1e3960b16872 100644 --- a/tool/m4/ruby_thread.m4 +++ b/tool/m4/ruby_thread.m4 @@ -16,4 +16,13 @@ AS_CASE(["$THREAD_MODEL"], [win32], [], [""], [AC_MSG_ERROR(thread model is missing)], [AC_MSG_ERROR(unknown thread model $THREAD_MODEL)]) + +THREAD_IMPL_H=thread_$THREAD_MODEL.h +AS_IF([test ! -f "$srcdir/$THREAD_IMPL_H"], + [AC_MSG_ERROR('$srcdir/$THREAD_IMPL_H' must exist)]) +THREAD_IMPL_SRC=thread_$THREAD_MODEL.c +AS_IF([test ! -f "$srcdir/$THREAD_IMPL_SRC"], + [AC_MSG_ERROR('$srcdir/$THREAD_IMPL_SRC' must exist)]) +AC_DEFINE_UNQUOTED(THREAD_IMPL_H, ["$THREAD_IMPL_H"]) +AC_DEFINE_UNQUOTED(THREAD_IMPL_SRC, ["$THREAD_IMPL_SRC"]) ])dnl diff --git a/vm_core.h b/vm_core.h index 96437ff559993b..2e022a6dd018e7 100644 --- a/vm_core.h +++ b/vm_core.h @@ -80,11 +80,7 @@ #include "darray.h" #include "ruby/thread_native.h" -#if defined(_WIN32) -#include "thread_win32.h" -#elif defined(HAVE_PTHREAD_H) -#include "thread_pthread.h" -#endif +#include THREAD_IMPL_H #define RUBY_VM_THREAD_MODEL 2 diff --git a/win32/Makefile.sub b/win32/Makefile.sub index 2aef63985b1967..ce8cafe8075a80 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -414,6 +414,8 @@ LIBRUBYARG_SHARED = $(LIBRUBY) LIBRUBY_RELATIVE = yes THREAD_MODEL = win32 +THREAD_IMPL_H = thread_$(THREAD_MODEL).h +THREAD_IMPL_SRC = thread_$(THREAD_MODEL).c !if "$(CROSS_COMPILING)" == "yes" PREP = $(arch)-fake.rb @@ -873,6 +875,8 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub #define STACK_GROW_DIRECTION -1 !endif #define COROUTINE_H "$(COROUTINE_H)" +#define THREAD_IMPL_H "$(THREAD_IMPL_H)" +#define THREAD_IMPL_SRC "$(THREAD_IMPL_SRC)" #define LOAD_RELATIVE 1 #define DLEXT ".so" !if "$(libdir_basename)" != "lib"