From bc648b12cbb35a8a553e7cc47ed2b4ba01906cbb Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 28 Jun 2017 04:49:30 +0000 Subject: introduce rb_thread_ptr() to replace GetThreadPtr(). * vm_core.h (rb_thread_ptr): added to replace GetThreadPtr() macro. * thread.c (in some functions: use "target_th" instead of "th" to make clear that it is not a current thread. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- cont.c | 7 +- thread.c | 241 +++++++++++++++++++++++---------------------------------- vm.c | 3 +- vm_backtrace.c | 9 +-- vm_core.h | 8 +- vm_dump.c | 15 ++-- vm_trace.c | 40 ++++------ 7 files changed, 131 insertions(+), 192 deletions(-) diff --git a/cont.c b/cont.c index 70ffd41e73..c17ee15807 100644 --- a/cont.c +++ b/cont.c @@ -196,9 +196,9 @@ cont_mark(void *ptr) } else { /* fiber */ - rb_thread_t *th; + rb_thread_t *th = rb_thread_ptr(cont->saved_thread.self); rb_fiber_t *fib = (rb_fiber_t*)cont; - GetThreadPtr(cont->saved_thread.self, th); + if ((th->fiber != fib) && fib->status == FIBER_RUNNING) { rb_gc_mark_locations(cont->machine.stack, cont->machine.stack + cont->machine.stack_size); @@ -1514,9 +1514,8 @@ rb_fiber_yield(int argc, const VALUE *argv) void rb_fiber_reset_root_local_storage(VALUE thval) { - rb_thread_t *th; + rb_thread_t *th = rb_thread_ptr(thval); - GetThreadPtr(thval, th); if (th->root_fiber && th->root_fiber != th->fiber) { th->ec.local_storage = th->root_fiber->cont.saved_thread.ec.local_storage; } diff --git a/thread.c b/thread.c index 6c7c9a900b..cb88611bda 100644 --- a/thread.c +++ b/thread.c @@ -712,14 +712,13 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s static VALUE thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS)) { - rb_thread_t *th, *current_th = GET_THREAD(); + rb_thread_t *th = rb_thread_ptr(thval), *current_th = GET_THREAD(); int err; if (OBJ_FROZEN(current_th->thgroup)) { rb_raise(rb_eThreadError, "can't start a new thread (frozen ThreadGroup)"); } - GetThreadPtr(thval, th); /* setup thread environment */ th->first_func = fn; @@ -781,7 +780,7 @@ thread_s_new(int argc, VALUE *argv, VALUE klass) rb_raise(rb_eThreadError, "can't alloc thread"); rb_obj_call_init(thread, argc, argv); - GetThreadPtr(thread, th); + th = rb_thread_ptr(thread); if (!threadptr_initialized(th)) { rb_raise(rb_eThreadError, "uninitialized thread - check `%"PRIsVALUE"#initialize'", klass); @@ -809,21 +808,23 @@ thread_start(VALUE klass, VALUE args) static VALUE thread_initialize(VALUE thread, VALUE args) { - rb_thread_t *th; + rb_thread_t *th = rb_thread_ptr(thread); + if (!rb_block_given_p()) { rb_raise(rb_eThreadError, "must be called with a block"); } - GetThreadPtr(thread, th); - if (th->first_args) { + else if (th->first_args) { VALUE proc = th->first_proc, loc; - if (!proc || !RTEST(loc = rb_proc_location(proc))) { - rb_raise(rb_eThreadError, "already initialized thread"); - } - rb_raise(rb_eThreadError, + if (!proc || !RTEST(loc = rb_proc_location(proc))) { + rb_raise(rb_eThreadError, "already initialized thread"); + } + rb_raise(rb_eThreadError, "already initialized thread - %"PRIsVALUE":%"PRIsVALUE, - RARRAY_AREF(loc, 0), RARRAY_AREF(loc, 1)); + RARRAY_AREF(loc, 0), RARRAY_AREF(loc, 1)); + } + else { + return thread_create_core(thread, args, 0); } - return thread_create_core(thread, args, 0); } VALUE @@ -987,18 +988,15 @@ thread_join(rb_thread_t *target_th, double delay) static VALUE thread_join_m(int argc, VALUE *argv, VALUE self) { - rb_thread_t *target_th; double delay = DELAY_INFTY; VALUE limit; - GetThreadPtr(self, target_th); - rb_scan_args(argc, argv, "01", &limit); if (!NIL_P(limit)) { delay = rb_num2dbl(limit); } - return thread_join(target_th, delay); + return thread_join(rb_thread_ptr(self), delay); } /* @@ -1018,8 +1016,7 @@ thread_join_m(int argc, VALUE *argv, VALUE self) static VALUE thread_value(VALUE self) { - rb_thread_t *th; - GetThreadPtr(self, th); + rb_thread_t *th = rb_thread_ptr(self); thread_join(th, DELAY_INFTY); return th->value; } @@ -1239,9 +1236,7 @@ rb_thread_check_trap_pending(void) int rb_thread_interrupted(VALUE thval) { - rb_thread_t *th; - GetThreadPtr(thval, th); - return (int)RUBY_VM_INTERRUPTED(th); + return (int)RUBY_VM_INTERRUPTED(rb_thread_ptr(thval)); } void @@ -1918,9 +1913,7 @@ rb_thread_s_handle_interrupt(VALUE self, VALUE mask_arg) static VALUE rb_thread_pending_interrupt_p(int argc, VALUE *argv, VALUE target_thread) { - rb_thread_t *target_th; - - GetThreadPtr(target_thread, target_th); + rb_thread_t *target_th = rb_thread_ptr(target_thread); if (!target_th->pending_interrupt_queue) { return Qfalse; @@ -2113,9 +2106,7 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing) void rb_thread_execute_interrupts(VALUE thval) { - rb_thread_t *th; - GetThreadPtr(thval, th); - rb_threadptr_execute_interrupts(th, 1); + rb_threadptr_execute_interrupts(rb_thread_ptr(thval), 1); } static void @@ -2254,15 +2245,15 @@ rb_thread_fd_close(int fd) static VALUE thread_raise_m(int argc, VALUE *argv, VALUE self) { - rb_thread_t *target_th; - rb_thread_t *th = GET_THREAD(); - GetThreadPtr(self, target_th); + rb_thread_t *target_th = rb_thread_ptr(self); + const rb_thread_t *current_th = GET_THREAD(); + threadptr_check_pending_interrupt_queue(target_th); rb_threadptr_raise(target_th, argc, argv); /* To perform Thread.current.raise as Kernel.raise */ - if (th == target_th) { - RUBY_VM_CHECK_INTS(th); + if (current_th == target_th) { + RUBY_VM_CHECK_INTS(target_th); } return Qnil; } @@ -2284,9 +2275,7 @@ thread_raise_m(int argc, VALUE *argv, VALUE self) VALUE rb_thread_kill(VALUE thread) { - rb_thread_t *th; - - GetThreadPtr(thread, th); + rb_thread_t *th = rb_thread_ptr(thread); if (th->to_kill || th->status == THREAD_KILLED) { return thread; @@ -2312,9 +2301,7 @@ rb_thread_kill(VALUE thread) int rb_thread_to_be_killed(VALUE thread) { - rb_thread_t *th; - - GetThreadPtr(thread, th); + rb_thread_t *th = rb_thread_ptr(thread); if (th->to_kill || th->status == THREAD_KILLED) { return TRUE; @@ -2391,15 +2378,16 @@ rb_thread_wakeup(VALUE thread) VALUE rb_thread_wakeup_alive(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); + rb_thread_t *target_th = rb_thread_ptr(thread); + if (target_th->status == THREAD_KILLED) return Qnil; - if (th->status == THREAD_KILLED) { - return Qnil; + rb_threadptr_ready(target_th); + + if (target_th->status == THREAD_STOPPED || + target_th->status == THREAD_STOPPED_FOREVER) { + target_th->status = THREAD_RUNNABLE; } - rb_threadptr_ready(th); - if (th->status == THREAD_STOPPED || th->status == THREAD_STOPPED_FOREVER) - th->status = THREAD_RUNNABLE; + return thread; } @@ -2626,9 +2614,7 @@ rb_thread_s_abort_exc_set(VALUE self, VALUE val) static VALUE rb_thread_abort_exc(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); - return th->abort_on_exception ? Qtrue : Qfalse; + return rb_thread_ptr(thread)->abort_on_exception ? Qtrue : Qfalse; } @@ -2648,10 +2634,7 @@ rb_thread_abort_exc(VALUE thread) static VALUE rb_thread_abort_exc_set(VALUE thread, VALUE val) { - rb_thread_t *th; - - GetThreadPtr(thread, th); - th->abort_on_exception = RTEST(val); + rb_thread_ptr(thread)->abort_on_exception = RTEST(val); return val; } @@ -2736,9 +2719,7 @@ rb_thread_s_report_exc_set(VALUE self, VALUE val) static VALUE rb_thread_report_exc(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); - return th->report_on_exception ? Qtrue : Qfalse; + return rb_thread_ptr(thread)->report_on_exception ? Qtrue : Qfalse; } @@ -2758,10 +2739,7 @@ rb_thread_report_exc(VALUE thread) static VALUE rb_thread_report_exc_set(VALUE thread, VALUE val) { - rb_thread_t *th; - - GetThreadPtr(thread, th); - th->report_on_exception = RTEST(val); + rb_thread_ptr(thread)->report_on_exception = RTEST(val); return val; } @@ -2779,15 +2757,8 @@ rb_thread_report_exc_set(VALUE thread, VALUE val) VALUE rb_thread_group(VALUE thread) { - rb_thread_t *th; - VALUE group; - GetThreadPtr(thread, th); - group = th->thgroup; - - if (!group) { - group = Qnil; - } - return group; + VALUE group = rb_thread_ptr(thread)->thgroup; + return group == 0 ? Qnil : group; } static const char * @@ -2795,10 +2766,7 @@ thread_status_name(rb_thread_t *th, int detail) { switch (th->status) { case THREAD_RUNNABLE: - if (th->to_kill) - return "aborting"; - else - return "run"; + return th->to_kill ? "aborting" : "run"; case THREAD_STOPPED_FOREVER: if (detail) return "sleep_forever"; case THREAD_STOPPED: @@ -2851,17 +2819,20 @@ rb_threadptr_dead(rb_thread_t *th) static VALUE rb_thread_status(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); + rb_thread_t *target_th = rb_thread_ptr(thread); - if (rb_threadptr_dead(th)) { - if (!NIL_P(th->errinfo) && !FIXNUM_P(th->errinfo) - /* TODO */ ) { + if (rb_threadptr_dead(target_th)) { + if (!NIL_P(target_th->errinfo) && + !FIXNUM_P(target_th->errinfo)) { return Qnil; } - return Qfalse; + else { + return Qfalse; + } + } + else { + return rb_str_new2(thread_status_name(target_th, FALSE)); } - return rb_str_new2(thread_status_name(th, FALSE)); } @@ -2882,12 +2853,12 @@ rb_thread_status(VALUE thread) static VALUE rb_thread_alive_p(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); - - if (rb_threadptr_dead(th)) + if (rb_threadptr_dead(rb_thread_ptr(thread))) { return Qfalse; - return Qtrue; + } + else { + return Qtrue; + } } /* @@ -2907,14 +2878,18 @@ rb_thread_alive_p(VALUE thread) static VALUE rb_thread_stop_p(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); + rb_thread_t *th = rb_thread_ptr(thread); - if (rb_threadptr_dead(th)) + if (rb_threadptr_dead(th)) { return Qtrue; - if (th->status == THREAD_STOPPED || th->status == THREAD_STOPPED_FOREVER) + } + else if (th->status == THREAD_STOPPED || + th->status == THREAD_STOPPED_FOREVER) { return Qtrue; - return Qfalse; + } + else { + return Qfalse; + } } /* @@ -2932,10 +2907,7 @@ rb_thread_stop_p(VALUE thread) static VALUE rb_thread_safe_level(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); - - return INT2NUM(th->ec.safe_level); + return INT2NUM(rb_thread_ptr(thread)->ec.safe_level); } /* @@ -2948,9 +2920,7 @@ rb_thread_safe_level(VALUE thread) static VALUE rb_thread_getname(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); - return th->name; + return rb_thread_ptr(thread)->name; } /* @@ -2967,8 +2937,8 @@ rb_thread_setname(VALUE thread, VALUE name) #ifdef SET_ANOTHER_THREAD_NAME const char *s = ""; #endif - rb_thread_t *th; - GetThreadPtr(thread, th); + rb_thread_t *target_th = rb_thread_ptr(thread); + if (!NIL_P(name)) { rb_encoding *enc; StringValueCStr(name); @@ -2982,10 +2952,10 @@ rb_thread_setname(VALUE thread, VALUE name) s = RSTRING_PTR(name); #endif } - th->name = name; + target_th->name = name; #if defined(SET_ANOTHER_THREAD_NAME) - if (threadptr_initialized(th)) { - SET_ANOTHER_THREAD_NAME(th->thread_id, s); + if (threadptr_initialized(target_th)) { + SET_ANOTHER_THREAD_NAME(target_th->thread_id, s); } #endif return name; @@ -3002,18 +2972,17 @@ static VALUE rb_thread_inspect(VALUE thread) { VALUE cname = rb_class_path(rb_obj_class(thread)); - rb_thread_t *th; + rb_thread_t *target_th = rb_thread_ptr(thread); const char *status; VALUE str; - GetThreadPtr(thread, th); - status = thread_status_name(th, TRUE); + status = thread_status_name(target_th, TRUE); str = rb_sprintf("#<%"PRIsVALUE":%p", cname, (void *)thread); - if (!NIL_P(th->name)) { - rb_str_catf(str, "@%"PRIsVALUE, th->name); + if (!NIL_P(target_th->name)) { + rb_str_catf(str, "@%"PRIsVALUE, target_th->name); } - if (!th->first_func && th->first_proc) { - VALUE loc = rb_proc_location(th->first_proc); + if (!target_th->first_func && target_th->first_proc) { + VALUE loc = rb_proc_location(target_th->first_proc); if (!NIL_P(loc)) { const VALUE *ptr = RARRAY_CONST_PTR(loc); rb_str_catf(str, "@%"PRIsVALUE":%"PRIsVALUE, ptr[0], ptr[1]); @@ -3051,9 +3020,7 @@ threadptr_local_aref(rb_thread_t *th, ID id) VALUE rb_thread_local_aref(VALUE thread, ID id) { - rb_thread_t *th; - GetThreadPtr(thread, th); - return threadptr_local_aref(th, id); + return threadptr_local_aref(rb_thread_ptr(thread), id); } /* @@ -3129,7 +3096,7 @@ rb_thread_fetch(int argc, VALUE *argv, VALUE self) { VALUE key, val; ID id; - rb_thread_t *th; + rb_thread_t *target_th = rb_thread_ptr(self); int block_given; rb_check_arity(argc, 1, 2); @@ -3141,12 +3108,12 @@ rb_thread_fetch(int argc, VALUE *argv, VALUE self) } id = rb_check_id(&key); - GetThreadPtr(self, th); if (id == recursive_key) { - return th->ec.local_storage_recursive_hash; + return target_th->ec.local_storage_recursive_hash; } - else if (id && th->ec.local_storage && st_lookup(th->ec.local_storage, id, &val)) { + else if (id && target_th->ec.local_storage && + st_lookup(target_th->ec.local_storage, id, &val)) { return val; } else if (block_given) { @@ -3188,14 +3155,11 @@ threadptr_local_aset(rb_thread_t *th, ID id, VALUE val) VALUE rb_thread_local_aset(VALUE thread, ID id, VALUE val) { - rb_thread_t *th; - GetThreadPtr(thread, th); - if (OBJ_FROZEN(thread)) { rb_error_frozen("thread locals"); } - return threadptr_local_aset(th, id, val); + return threadptr_local_aset(rb_thread_ptr(thread), id, val); } /* @@ -3292,12 +3256,8 @@ rb_thread_variable_set(VALUE thread, VALUE id, VALUE val) static VALUE rb_thread_key_p(VALUE self, VALUE key) { - rb_thread_t *th; ID id = rb_check_id(&key); - st_table *local_storage; - - GetThreadPtr(self, th); - local_storage= th->ec.local_storage; + st_table *local_storage = rb_thread_ptr(self)->ec.local_storage; if (!id || local_storage == NULL) { return Qfalse; @@ -3340,12 +3300,11 @@ rb_thread_alone(void) static VALUE rb_thread_keys(VALUE self) { - rb_thread_t *th; + st_table *local_storage = rb_thread_ptr(self)->ec.local_storage; VALUE ary = rb_ary_new(); - GetThreadPtr(self, th); - if (th->ec.local_storage) { - st_foreach(th->ec.local_storage, thread_keys_i, ary); + if (local_storage) { + st_foreach(local_storage, thread_keys_i, ary); } return ary; } @@ -3441,9 +3400,7 @@ rb_thread_variable_p(VALUE thread, VALUE key) static VALUE rb_thread_priority(VALUE thread) { - rb_thread_t *th; - GetThreadPtr(thread, th); - return INT2NUM(th->priority); + return INT2NUM(rb_thread_ptr(thread)->priority); } @@ -3476,13 +3433,11 @@ rb_thread_priority(VALUE thread) static VALUE rb_thread_priority_set(VALUE thread, VALUE prio) { - rb_thread_t *th; + rb_thread_t *target_th = rb_thread_ptr(thread); int priority; - GetThreadPtr(thread, th); - #if USE_NATIVE_THREAD_PRIORITY - th->priority = NUM2INT(prio); + target_th->priority = NUM2INT(prio); native_thread_apply_priority(th); #else priority = NUM2INT(prio); @@ -3492,9 +3447,9 @@ rb_thread_priority_set(VALUE thread, VALUE prio) else if (priority < RUBY_THREAD_PRIORITY_MIN) { priority = RUBY_THREAD_PRIORITY_MIN; } - th->priority = priority; + target_th->priority = priority; #endif - return INT2NUM(th->priority); + return INT2NUM(target_th->priority); } /* for IO */ @@ -4379,11 +4334,9 @@ thgroup_enclosed_p(VALUE group) static VALUE thgroup_add(VALUE group, VALUE thread) { - rb_thread_t *th; + rb_thread_t *target_th = rb_thread_ptr(thread); struct thgroup *data; - GetThreadPtr(thread, th); - if (OBJ_FROZEN(group)) { rb_raise(rb_eThreadError, "can't move to the frozen thread group"); } @@ -4392,20 +4345,20 @@ thgroup_add(VALUE group, VALUE thread) rb_raise(rb_eThreadError, "can't move to the enclosed thread group"); } - if (!th->thgroup) { + if (!target_th->thgroup) { return Qnil; } - if (OBJ_FROZEN(th->thgroup)) { + if (OBJ_FROZEN(target_th->thgroup)) { rb_raise(rb_eThreadError, "can't move from the frozen thread group"); } - TypedData_Get_Struct(th->thgroup, struct thgroup, &thgroup_data_type, data); + TypedData_Get_Struct(target_th->thgroup, struct thgroup, &thgroup_data_type, data); if (data->enclosed) { rb_raise(rb_eThreadError, "can't move from the enclosed thread group"); } - th->thgroup = group; + target_th->thgroup = group; return group; } diff --git a/vm.c b/vm.c index 6f1cc71f32..d5382125b8 100644 --- a/vm.c +++ b/vm.c @@ -2555,9 +2555,8 @@ th_init(rb_thread_t *th, VALUE self) static VALUE ruby_thread_init(VALUE self) { - rb_thread_t *th; + rb_thread_t *th = rb_thread_ptr(self); rb_vm_t *vm = GET_THREAD()->vm; - GetThreadPtr(self, th); th->vm = vm; th_init(th, self); diff --git a/vm_backtrace.c b/vm_backtrace.c index ed0b33c8da..aab62ea072 100644 --- a/vm_backtrace.c +++ b/vm_backtrace.c @@ -889,13 +889,12 @@ threadptr_backtrace_to_ary(rb_thread_t *th, int argc, const VALUE *argv, int lev static VALUE thread_backtrace_to_ary(int argc, const VALUE *argv, VALUE thval, int to_str) { - rb_thread_t *th; - GetThreadPtr(thval, th); + rb_thread_t *target_th = rb_thread_ptr(thval); - if (th->to_kill || th->status == THREAD_KILLED) - return Qnil; + if (target_th->to_kill || target_th->status == THREAD_KILLED) + return Qnil; - return threadptr_backtrace_to_ary(th, argc, argv, 0, 0, to_str); + return threadptr_backtrace_to_ary(target_th, argc, argv, 0, 0, to_str); } VALUE diff --git a/vm_core.h b/vm_core.h index 4a21ba27b0..da2236e581 100644 --- a/vm_core.h +++ b/vm_core.h @@ -672,8 +672,12 @@ typedef struct rb_control_frame_struct { extern const rb_data_type_t ruby_threadptr_data_type; -#define GetThreadPtr(obj, ptr) \ - TypedData_Get_Struct((obj), rb_thread_t, &ruby_threadptr_data_type, (ptr)) +static inline struct rb_thread_struct * +rb_thread_ptr(VALUE thval) +{ + VM_ASSERT(rb_check_typeddata(obj, &ruby_threadptr_data_type) != NULL); + return (struct rb_thread_struct *)DATA_PTR(thval); +} enum rb_thread_status { THREAD_RUNNABLE, diff --git a/vm_dump.c b/vm_dump.c index 148790da79..dbd9c6bb89 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -212,9 +212,8 @@ rb_vmdebug_proc_dump_raw(rb_proc_t *proc) void rb_vmdebug_stack_dump_th(VALUE thval) { - rb_thread_t *th; - GetThreadPtr(thval, th); - rb_vmdebug_stack_dump_raw(th, th->ec.cfp); + rb_thread_t *target_th = rb_thread_ptr(thval); + rb_vmdebug_stack_dump_raw(target_th, target_th->ec.cfp); } #if VMDEBUG > 2 @@ -327,9 +326,7 @@ rb_vmdebug_debug_print_register(rb_thread_t *th) void rb_vmdebug_thread_dump_regs(VALUE thval) { - rb_thread_t *th; - GetThreadPtr(thval, th); - rb_vmdebug_debug_print_register(th); + rb_vmdebug_debug_print_register(rb_thread_ptr(thval)); } void @@ -399,10 +396,8 @@ rb_vmdebug_debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp VALUE rb_vmdebug_thread_dump_state(VALUE self) { - rb_thread_t *th; - rb_control_frame_t *cfp; - GetThreadPtr(self, th); - cfp = th->ec.cfp; + rb_thread_t *th = rb_thread_ptr(self); + rb_control_frame_t *cfp = th->ec.cfp; fprintf(stderr, "Thread state dump:\n"); fprintf(stderr, "pc : %p, sp : %p\n", (void *)cfp->pc, (void *)cfp->sp); diff --git a/vm_trace.c b/vm_trace.c index e970dfcae2..0f2323284f 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -92,14 +92,6 @@ recalc_remove_ruby_vm_event_flags(rb_event_flag_t events) /* add/remove hooks */ -static rb_thread_t * -thval2thread_t(VALUE thval) -{ - rb_thread_t *th; - GetThreadPtr(thval, th); - return th; -} - static rb_event_hook_t * alloc_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags) { @@ -136,7 +128,7 @@ rb_threadptr_add_event_hook(rb_thread_t *th, rb_event_hook_func_t func, rb_event void rb_thread_add_event_hook(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data) { - rb_threadptr_add_event_hook(thval2thread_t(thval), func, events, data, RUBY_EVENT_HOOK_FLAG_SAFE); + rb_threadptr_add_event_hook(rb_thread_ptr(thval), func, events, data, RUBY_EVENT_HOOK_FLAG_SAFE); } void @@ -149,7 +141,7 @@ rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data) void rb_thread_add_event_hook2(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags) { - rb_threadptr_add_event_hook(thval2thread_t(thval), func, events, data, hook_flags); + rb_threadptr_add_event_hook(rb_thread_ptr(thval), func, events, data, hook_flags); } void @@ -189,13 +181,13 @@ rb_threadptr_remove_event_hook(rb_thread_t *th, rb_event_hook_func_t func, VALUE int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func) { - return rb_threadptr_remove_event_hook(thval2thread_t(thval), func, Qundef); + return rb_threadptr_remove_event_hook(rb_thread_ptr(thval), func, Qundef); } int rb_thread_remove_event_hook_with_data(VALUE thval, rb_event_hook_func_t func, VALUE data) { - return rb_threadptr_remove_event_hook(thval2thread_t(thval), func, data); + return rb_threadptr_remove_event_hook(rb_thread_ptr(thval), func, data); } int @@ -519,10 +511,7 @@ thread_add_trace_func(rb_thread_t *th, VALUE trace) static VALUE thread_add_trace_func_m(VALUE obj, VALUE trace) { - rb_thread_t *th; - - GetThreadPtr(obj, th); - thread_add_trace_func(th, trace); + thread_add_trace_func(rb_thread_ptr(obj), trace); return trace; } @@ -538,19 +527,19 @@ thread_add_trace_func_m(VALUE obj, VALUE trace) */ static VALUE -thread_set_trace_func_m(VALUE obj, VALUE trace) +thread_set_trace_func_m(VALUE target_thread, VALUE trace) { - rb_thread_t *th; + rb_thread_t *target_th = rb_thread_ptr(target_thread); - GetThreadPtr(obj, th); - rb_threadptr_remove_event_hook(th, call_trace_func, Qundef); + rb_threadptr_remove_event_hook(target_th, call_trace_func, Qundef); if (NIL_P(trace)) { return Qnil; } - - thread_add_trace_func(th, trace); - return trace; + else { + thread_add_trace_func(target_th, trace); + return trace; + } } static const char * @@ -1218,9 +1207,10 @@ tracepoint_new(VALUE klass, rb_thread_t *target_th, rb_event_flag_t events, void VALUE rb_tracepoint_new(VALUE target_thval, rb_event_flag_t events, void (*func)(VALUE, void *), void *data) { - rb_thread_t *target_th = 0; + rb_thread_t *target_th = NULL; + if (RTEST(target_thval)) { - GetThreadPtr(target_thval, target_th); + target_th = rb_thread_ptr(target_thval); /* TODO: Test it! * Warning: This function is not tested. */ -- cgit v1.2.3