1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Make Thread#native_thread_id not-implemented if unsupported

Raise `NotImplementedError` on unsupported platforms regardless
the argument consistently.
This commit is contained in:
Nobuyoshi Nakada 2021-06-01 22:27:13 +09:00
parent 6e7e9a80ad
commit 9024c7f1bb
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
4 changed files with 11 additions and 5 deletions

View file

@ -1335,7 +1335,7 @@ q.pop
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}

View file

@ -3402,6 +3402,7 @@ rb_thread_setname(VALUE thread, VALUE name)
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)
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:

View file

@ -1726,13 +1726,10 @@ native_set_another_thread_name(rb_nativethread_id_t thread_id, VALUE name)
#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)
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)

View file

@ -842,6 +842,7 @@ native_thread_native_thread_id(rb_thread_t *th)
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