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:
parent
6e7e9a80ad
commit
9024c7f1bb
4 changed files with 11 additions and 5 deletions
|
@ -1335,7 +1335,7 @@ q.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_thread_native_thread_id
|
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
|
assert_instance_of Integer, Thread.main.native_thread_id
|
||||||
|
|
||||||
th1 = Thread.start{sleep}
|
th1 = Thread.start{sleep}
|
||||||
|
|
4
thread.c
4
thread.c
|
@ -3402,6 +3402,7 @@ rb_thread_setname(VALUE thread, VALUE name)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_NATIVE_THREAD_NATIVE_THREAD_ID
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* thr.native_thread_id -> integer
|
* thr.native_thread_id -> integer
|
||||||
|
@ -3431,6 +3432,9 @@ rb_thread_native_thread_id(VALUE thread)
|
||||||
if (rb_threadptr_dead(target_th)) return Qnil;
|
if (rb_threadptr_dead(target_th)) return Qnil;
|
||||||
return native_thread_native_thread_id(target_th);
|
return native_thread_native_thread_id(target_th);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
# define rb_thread_native_thread_id rb_f_notimplement
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
|
|
|
@ -1726,13 +1726,10 @@ native_set_another_thread_name(rb_nativethread_id_t thread_id, VALUE name)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(RB_THREAD_T_HAS_NATIVE_ID) || defined(__APPLE__)
|
||||||
static VALUE
|
static VALUE
|
||||||
native_thread_native_thread_id(rb_thread_t *target_th)
|
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
|
#ifdef RB_THREAD_T_HAS_NATIVE_ID
|
||||||
int tid = target_th->tid;
|
int tid = target_th->tid;
|
||||||
if (tid == 0) return Qnil;
|
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);
|
return ULL2NUM((unsigned long long)tid);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
# define USE_NATIVE_THREAD_NATIVE_THREAD_ID 1
|
||||||
|
#else
|
||||||
|
# define USE_NATIVE_THREAD_NATIVE_THREAD_ID 0
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ubf_timer_invalidate(void)
|
ubf_timer_invalidate(void)
|
||||||
|
|
|
@ -842,6 +842,7 @@ native_thread_native_thread_id(rb_thread_t *th)
|
||||||
if (tid == 0) rb_sys_fail("GetThreadId");
|
if (tid == 0) rb_sys_fail("GetThreadId");
|
||||||
return ULONG2NUM(tid);
|
return ULONG2NUM(tid);
|
||||||
}
|
}
|
||||||
|
#define USE_NATIVE_THREAD_NATIVE_THREAD_ID 1
|
||||||
|
|
||||||
#if USE_MJIT
|
#if USE_MJIT
|
||||||
static unsigned long __stdcall
|
static unsigned long __stdcall
|
||||||
|
|
Loading…
Add table
Reference in a new issue