remove `NON_SCALAR_THREAD_ID` support

`NON_SCALAR_THREAD_ID` shows `pthread_t` is non-scalar (non-pointer)
and only s390x is known platform. However, the supporting code is
very complex and it is only used for deubg print information.

So this patch removes the support of `NON_SCALAR_THREAD_ID`
and make the code simple.
This commit is contained in:
Koichi Sasada 2022-05-24 02:56:59 +09:00
Родитель 741ac50330
Коммит d9984f39d3
7 изменённых файлов: 10 добавлений и 61 удалений

Просмотреть файл

@ -270,34 +270,6 @@ void rb_thread_debug(const char *fmt, ...);
#define POSITION_ARGS
#endif
# ifdef NON_SCALAR_THREAD_ID
#define fill_thread_id_string ruby_fill_thread_id_string
const char *
ruby_fill_thread_id_string(rb_nativethread_id_t thid, rb_thread_id_string_t buf)
{
extern const char ruby_digitmap[];
size_t i;
buf[0] = '0';
buf[1] = 'x';
for (i = 0; i < sizeof(thid); i++) {
# ifdef LITTLE_ENDIAN
size_t j = sizeof(thid) - i - 1;
# else
size_t j = i;
# endif
unsigned char c = (unsigned char)((char *)&thid)[j];
buf[2 + i * 2] = ruby_digitmap[(c >> 4) & 0xf];
buf[3 + i * 2] = ruby_digitmap[c & 0xf];
}
buf[sizeof(rb_thread_id_string_t)-1] = '\0';
return buf;
}
# define fill_thread_id_str(th) fill_thread_id_string((th)->thread_id, (th)->thread_id_string)
# define thread_id_str(th) ((th)->thread_id_string)
# define PRI_THREAD_ID "s"
# endif
# if THREAD_DEBUG < 0
static int rb_thread_debug_enabled;
@ -336,12 +308,8 @@ rb_thread_s_debug_set(VALUE self, VALUE val)
#define thread_debug if(0)printf
#endif
#ifndef fill_thread_id_str
# define fill_thread_id_string(thid, buf) ((void *)(uintptr_t)(thid))
# define fill_thread_id_str(th) (void)0
# define thread_id_str(th) ((void *)(uintptr_t)(th)->nt->thread_id)
# define PRI_THREAD_ID "p"
#endif
#define thread_id_str(th) ((void *)(uintptr_t)(th)->nt->thread_id)
#define PRI_THREAD_ID "p"
MAYBE_UNUSED(NOINLINE(static int thread_start_func_2(rb_thread_t *th, VALUE *stack_start)));
void ruby_sigchld_handler(rb_vm_t *); /* signal.c */
@ -380,9 +348,6 @@ rb_thread_debug(
{
va_list args;
char buf[BUFSIZ];
#ifdef NON_SCALAR_THREAD_ID
rb_thread_id_string_t thread_id_string;
#endif
if (!rb_thread_debug_enabled) return;

Просмотреть файл

@ -130,7 +130,6 @@ Init_native_thread(rb_thread_t *main_th)
{
// no TLS setup and no thread id setup
ruby_thread_set_native(main_th);
fill_thread_id_str(main_th);
}
static void

Просмотреть файл

@ -51,10 +51,15 @@
# define USE_EVENTFD (0)
#endif
#ifdef NON_SCALAR_THREAD_ID
#define DEBUG_OUT_NT_ID (NULL)
#else
#define DEBUG_OUT_NT_ID ((void *)pthread_self())
#endif
#define DEBUG_OUT() \
pthread_mutex_lock(&debug_mutex); \
printf(POSITION_FORMAT"%"PRI_THREAD_ID" - %s" POSITION_ARGS, \
fill_thread_id_string(pthread_self(), thread_id_string), buf); \
printf(POSITION_FORMAT"%"PRI_THREAD_ID" - %s" POSITION_ARGS, DEBUG_OUT_NT_ID, buf); \
fflush(stdout); \
pthread_mutex_unlock(&debug_mutex);
@ -717,7 +722,6 @@ Init_native_thread(rb_thread_t *main_th)
// setup main thread
main_th->nt->thread_id = pthread_self();
ruby_thread_set_native(main_th);
fill_thread_id_str(main_th);
native_thread_init(main_th->nt);
}
@ -1069,7 +1073,6 @@ thread_start_func_1(void *th_ptr)
VALUE stack_start;
#endif
fill_thread_id_str(th);
#if defined USE_NATIVE_THREAD_INIT
native_thread_init_stack(th);
#endif
@ -1173,7 +1176,6 @@ use_cached_thread(rb_thread_t *th)
entry->th = th;
/* th->nt->thread_id must be set before signal for Thread#name= */
th->nt->thread_id = entry->thread_id;
fill_thread_id_str(th);
rb_native_cond_signal(&entry->cond);
}
rb_native_mutex_unlock(&thread_cache_lock);
@ -1237,7 +1239,6 @@ native_thread_create(rb_thread_t *th)
err = pthread_create(&th->nt->thread_id, &attr, thread_start_func_1, th);
thread_debug("create: %p (%d)\n", (void *)th, err);
/* should be done in the created thread */
fill_thread_id_str(th);
CHECK_ERR(pthread_attr_destroy(&attr));
}
return err;

Просмотреть файл

@ -30,10 +30,6 @@ struct rb_native_thread {
rb_nativethread_id_t thread_id;
#ifdef NON_SCALAR_THREAD_ID
rb_thread_id_string_t thread_id_string;
#endif
#ifdef RB_THREAD_T_HAS_NATIVE_ID
int tid;
#endif

4
vm.c
Просмотреть файл

@ -3275,10 +3275,6 @@ th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm)
th->top_self = vm->top_self; // 0 while self == 0
th->value = Qundef;
#if defined(NON_SCALAR_THREAD_ID) && !defined(__wasm__) && !defined(__EMSCRIPTEN__)
th->nt->thread_id_string[0] = '\0';
#endif
th->ec->errinfo = Qnil;
th->ec->root_svar = Qfalse;
th->ec->local_storage_recursive_hash = Qnil;

Просмотреть файл

@ -896,8 +896,6 @@ typedef struct rb_ensure_list {
struct rb_ensure_entry entry;
} rb_ensure_list_t;
typedef char rb_thread_id_string_t[sizeof(rb_nativethread_id_t) * 2 + 3];
typedef struct rb_fiber_struct rb_fiber_t;
struct rb_waiting_list {

Просмотреть файл

@ -1180,10 +1180,6 @@ rb_vm_bugreport(const void *ctx)
}
}
#ifdef NON_SCALAR_THREAD_ID
const char *ruby_fill_thread_id_string(rb_nativethread_id_t thid, rb_thread_id_string_t buf);
#endif
void
rb_vmdebug_stack_dump_all_threads(void)
{
@ -1193,9 +1189,7 @@ rb_vmdebug_stack_dump_all_threads(void)
// TODO: now it only shows current ractor
ccan_list_for_each(&r->threads.set, th, lt_node) {
#ifdef NON_SCALAR_THREAD_ID
rb_thread_id_string_t buf;
ruby_fill_thread_id_string(th->nt->thread_id, buf);
fprintf(stderr, "th: %p, native_id: %s\n", th, buf);
fprintf(stderr, "th: %p, native_id: N/A\n", th);
#else
fprintf(stderr, "th: %p, native_id: %p\n", (void *)th, (void *)(uintptr_t)th->nt->thread_id);
#endif