From 2093e4c2db1e19991e601bf5191eddb4652de35d Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 31 Mar 2023 03:52:58 +0900 Subject: `nt->serial` for `RUBY_DEBUG_LOG` Show native thread's serial on `RUBY_DEBUG_LOG`. `nt->serial` is also stored into `ruby_nt_serial` if the compiler supports `RB_THREAD_LOCAL_SPECIFIER`. --- thread_pthread.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'thread_pthread.c') diff --git a/thread_pthread.c b/thread_pthread.c index d5a00ff84a..9fe561a789 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1157,6 +1157,11 @@ static void * thread_start_func_1(void *th_ptr) { rb_thread_t *th = th_ptr; + +#if USE_RUBY_DEBUG_LOG && defined(RUBY_NT_SERIAL) + ruby_nt_serial = th->nt->serial; +#endif + RB_ALTSTACK_INIT(void *altstack, th->nt->altstack); #if USE_THREAD_CACHE thread_start: @@ -1298,13 +1303,24 @@ clear_thread_cache_altstack(void) } #endif +static struct rb_native_thread * +native_thread_alloc(void) +{ + struct rb_native_thread *nt = ZALLOC(struct rb_native_thread); +#if USE_RUBY_DEBUG_LOG + static rb_atomic_t nt_serial = 1; + nt->serial = RUBY_ATOMIC_FETCH_ADD(nt_serial, 1); +#endif + return nt; +} + static int native_thread_create(rb_thread_t *th) { int err = 0; VM_ASSERT(th->nt == 0); - th->nt = ZALLOC(struct rb_native_thread); + th->nt = native_thread_alloc(); if (use_cached_thread(th)) { RUBY_DEBUG_LOG("use cached nt. th:%u", rb_th_serial(th)); -- cgit v1.2.3