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`.
This commit is contained in:
Jun Aruga 2025-09-04 18:59:42 +01:00 committed by Jun Aruga
parent 1213adfe55
commit 971174054a
3 changed files with 8 additions and 4 deletions

View File

@ -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;

2
vm.c
View File

@ -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)
{

View File

@ -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;