diff options
author | Koichi Sasada <[email protected]> | 2023-03-31 03:52:58 +0900 |
---|---|---|
committer | Koichi Sasada <[email protected]> | 2023-03-31 11:28:18 +0900 |
commit | 2093e4c2db1e19991e601bf5191eddb4652de35d (patch) | |
tree | 486cb12704655596fdec0227a37450da23d8b5f4 /thread_pthread.c | |
parent | 83667008b925c32b3ab70fb6ec70f7398e960d1e (diff) |
`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`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7630
Diffstat (limited to 'thread_pthread.c')
-rw-r--r-- | thread_pthread.c | 18 |
1 files changed, 17 insertions, 1 deletions
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)); |