ruby-changes:71933
From: Koichi <ko1@a...>
Date: Tue, 24 May 2022 10:07:16 +0900 (JST)
Subject: [ruby-changes:71933] d9984f39d3 (master): remove `NON_SCALAR_THREAD_ID` support
https://git.ruby-lang.org/ruby.git/commit/?id=d9984f39d3 From d9984f39d32f4cd692a35f4d803f7754ea262805 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Tue, 24 May 2022 02:56:59 +0900 Subject: 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. --- thread.c | 39 ++------------------------------------- thread_none.c | 1 - thread_pthread.c | 13 +++++++------ thread_pthread.h | 4 ---- vm.c | 4 ---- vm_core.h | 2 -- vm_dump.c | 8 +------- 7 files changed, 10 insertions(+), 61 deletions(-) diff --git a/thread.c b/thread.c index bb9070f705..cee0c6c8de 100644 --- a/thread.c +++ b/thread.c @@ -270,34 +270,6 @@ void rb_thread_debug(const char *fmt, ...); https://github.com/ruby/ruby/blob/trunk/thread.c#L270 #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) https://github.com/ruby/ruby/blob/trunk/thread.c#L308 #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( https://github.com/ruby/ruby/blob/trunk/thread.c#L348 { 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; diff --git a/thread_none.c b/thread_none.c index 18986d3c5b..b57e082543 100644 --- a/thread_none.c +++ b/thread_none.c @@ -130,7 +130,6 @@ Init_native_thread(rb_thread_t *main_th) https://github.com/ruby/ruby/blob/trunk/thread_none.c#L130 { // no TLS setup and no thread id setup ruby_thread_set_native(main_th); - fill_thread_id_str(main_th); } static void diff --git a/thread_pthread.c b/thread_pthread.c index c825b731a6..c189a8130c 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -51,10 +51,15 @@ https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L51 # 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) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L722 // 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) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1073 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) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1176 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) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1239 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; diff --git a/thread_pthread.h b/thread_pthread.h index 3f6db3ed03..8e8c1eb43d 100644 --- a/thread_pthread.h +++ b/thread_pthread.h @@ -30,10 +30,6 @@ struct rb_native_thread { https://github.com/ruby/ruby/blob/trunk/thread_pthread.h#L30 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 diff --git a/vm.c b/vm.c index 3b478d848a..76041b0b91 100644 --- a/vm.c +++ b/vm.c @@ -3275,10 +3275,6 @@ th_init(rb_thread_t *th, VALUE self, rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/vm.c#L3275 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; diff --git a/vm_core.h b/vm_core.h index f25b74dcdd..4de0777292 100644 --- a/vm_core.h +++ b/vm_core.h @@ -896,8 +896,6 @@ typedef struct rb_ensure_list { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L896 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 { diff --git a/vm_dump.c b/vm_dump.c index ebc9a03680..5c79e80352 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -1180,10 +1180,6 @@ rb_vm_bugreport(const void *ctx) https://github.com/ruby/ruby/blob/trunk/vm_dump.c#L1180 } } -#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) https://github.com/ruby/ruby/blob/trunk/vm_dump.c#L1189 // 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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/