ruby-changes:66395
From: Nobuyoshi <ko1@a...>
Date: Tue, 1 Jun 2021 22:32:31 +0900 (JST)
Subject: [ruby-changes:66395] 9024c7f1bb (master): Make `Thread#native_thread_id` not-implemented if unsupported
https://git.ruby-lang.org/ruby.git/commit/?id=9024c7f1bb From 9024c7f1bb3ea432a2b52e7c701b06f83aafd4d5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 1 Jun 2021 22:27:13 +0900 Subject: Make `Thread#native_thread_id` not-implemented if unsupported Raise `NotImplementedError` on unsupported platforms regardless the argument consistently. --- test/ruby/test_thread.rb | 2 +- thread.c | 4 ++++ thread_pthread.c | 9 +++++---- thread_win32.c | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index a16f066..dbd0328 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -1335,7 +1335,7 @@ q.pop https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L1335 end def test_thread_native_thread_id - skip "don't support native_thread_id" unless (begin; Thread.main.native_thread_id; rescue NotImplementedError; nil; end) + skip "don't support native_thread_id" unless Thread.method_defined?(:native_thread_id) assert_instance_of Integer, Thread.main.native_thread_id th1 = Thread.start{sleep} diff --git a/thread.c b/thread.c index e36ea61..419bf09 100644 --- a/thread.c +++ b/thread.c @@ -3402,6 +3402,7 @@ rb_thread_setname(VALUE thread, VALUE name) https://github.com/ruby/ruby/blob/trunk/thread.c#L3402 return name; } +#if USE_NATIVE_THREAD_NATIVE_THREAD_ID /* * call-seq: * thr.native_thread_id -> integer @@ -3431,6 +3432,9 @@ rb_thread_native_thread_id(VALUE thread) https://github.com/ruby/ruby/blob/trunk/thread.c#L3432 if (rb_threadptr_dead(target_th)) return Qnil; return native_thread_native_thread_id(target_th); } +#else +# define rb_thread_native_thread_id rb_f_notimplement +#endif /* * call-seq: diff --git a/thread_pthread.c b/thread_pthread.c index 87db59e..8e98307 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1726,13 +1726,10 @@ native_set_another_thread_name(rb_nativethread_id_t thread_id, VALUE name) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1726 #endif } +#if defined(RB_THREAD_T_HAS_NATIVE_ID) || defined(__APPLE__) static VALUE native_thread_native_thread_id(rb_thread_t *target_th) { -#if !defined(RB_THREAD_T_HAS_NATIVE_ID) && !defined(__APPLE__) - rb_notimplement(); -#endif - #ifdef RB_THREAD_T_HAS_NATIVE_ID int tid = target_th->tid; if (tid == 0) return Qnil; @@ -1744,6 +1741,10 @@ native_thread_native_thread_id(rb_thread_t *target_th) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1741 return ULL2NUM((unsigned long long)tid); #endif } +# define USE_NATIVE_THREAD_NATIVE_THREAD_ID 1 +#else +# define USE_NATIVE_THREAD_NATIVE_THREAD_ID 0 +#endif static void ubf_timer_invalidate(void) diff --git a/thread_win32.c b/thread_win32.c index fc31c09..84b8776 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -842,6 +842,7 @@ native_thread_native_thread_id(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L842 if (tid == 0) rb_sys_fail("GetThreadId"); return ULONG2NUM(tid); } +#define USE_NATIVE_THREAD_NATIVE_THREAD_ID 1 #if USE_MJIT static unsigned long __stdcall -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/