From 971174054a26be0a4becbe7c67a7cc980158abf2 Mon Sep 17 00:00:00 2001 From: Jun Aruga Date: Thu, 4 Sep 2025 18:59:42 +0100 Subject: [PATCH] Add a macro to manage the condition of no-inline version rb_current_ec Add the macro `RB_THREAD_CURRENT_EC_NOINLINE` to manage the condition to use no-inline version rb_current_ec for a better maintainability. Note that the `vm_core.h` includes the `THREAD_IMPL_H` by the `#include THREAD_IMPL_H`. The `THREAD_IMPL_H` can be `thread_none.h`, `thread_pthread.h` or `thread_win32.h` according to the `tool/m4/ruby_thread.m4` creating the `THREAD_IMPL_H`. The change in this commit only defining the `RB_THREAD_CURRENT_EC_NOINLINE` in the `thread_pthread.h` is okay in this situation. Because in the `thread_none.h` case, the thread feature is not used at all, including Thread-Local Storage (TLS), and in the `thread_win32.h` case, the `RB_THREAD_LOCAL_SPECIFIER` is not defined. In the `thread_pthread.h` case, the `RB_THREAD_LOCAL_SPECIFIER` is defined in the `configure.ac`. In the `thread_none.h` case, the `RB_THREAD_LOCAL_SPECIFIER` is defined in the `thread_none.h`. --- thread_pthread.h | 8 ++++++-- vm.c | 2 +- vm_core.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/thread_pthread.h b/thread_pthread.h index 20a3876759..d635948c4b 100644 --- a/thread_pthread.h +++ b/thread_pthread.h @@ -17,6 +17,11 @@ #define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER #define RB_NATIVETHREAD_COND_INIT PTHREAD_COND_INITIALIZER +// TLS can not be accessed across .so on arm64 and perhaps ppc64le too. +#if defined(__arm64__) || defined(__aarch64__) || defined(__powerpc64__) +# define RB_THREAD_CURRENT_EC_NOINLINE +#endif + // this data should be protected by timer_th.waiting_lock struct rb_thread_sched_waiting { enum thread_sched_waiting_flag { @@ -133,8 +138,7 @@ struct rb_thread_sched { #ifdef RB_THREAD_LOCAL_SPECIFIER NOINLINE(void rb_current_ec_set(struct rb_execution_context_struct *)); - # if defined(__arm64__) || defined(__aarch64__) || defined(__powerpc64__) - // TLS can not be accessed across .so on arm64 and perhaps ppc64le too. + # ifdef RB_THREAD_CURRENT_EC_NOINLINE NOINLINE(struct rb_execution_context_struct *rb_current_ec(void)); # else RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER struct rb_execution_context_struct *ruby_current_ec; diff --git a/vm.c b/vm.c index e97619cc14..da92c5bd00 100644 --- a/vm.c +++ b/vm.c @@ -594,7 +594,7 @@ rb_current_ec_set(rb_execution_context_t *ec) } -#if defined(__arm64__) || defined(__aarch64__) || defined(__powerpc64__) +#ifdef RB_THREAD_CURRENT_EC_NOINLINE rb_execution_context_t * rb_current_ec(void) { diff --git a/vm_core.h b/vm_core.h index 1d02298c6c..9156b72868 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1999,7 +1999,7 @@ static inline rb_execution_context_t * rb_current_execution_context(bool expect_ec) { #ifdef RB_THREAD_LOCAL_SPECIFIER - #if defined(__arm64__) || defined(__aarch64__) || defined(__powerpc64__) + #ifdef RB_THREAD_CURRENT_EC_NOINLINE rb_execution_context_t * volatile ec = rb_current_ec(); #else rb_execution_context_t * volatile ec = ruby_current_ec;