Project

General

Profile

Feature #11098 » thread-local.patch

jasonrclark (Jason Clark), 04/25/2015 04:19 PM

View differences:

gc.c
#endif
objspace->total_allocated_objects++;
rb_thread_t *th = GET_THREAD();
th->allocated_objects++;
gc_event_hook(objspace, RUBY_INTERNAL_EVENT_NEWOBJ, obj);
gc_report(5, objspace, "newobj: %s\n", obj_info(obj));
test/ruby/test_thread.rb
t.new {}
end
end
def test_thread_allocated_objects
count = 0
t = Thread.new do
1000.times do
Object.new
end
count += Thread.current.allocated_objects
end
t.join
assert_equal 1000, count
end
end
thread.c
return group;
}
VALUE
rb_thread_allocated_objects(VALUE thread)
{
rb_thread_t *th;
GetThreadPtr(thread, th);
return LONG2NUM(th->allocated_objects);
}
static const char *
thread_status_name(rb_thread_t *th)
{
......
rb_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1);
rb_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0);
rb_define_method(rb_cThread, "group", rb_thread_group, 0);
rb_define_method(rb_cThread, "allocated_objects", rb_thread_allocated_objects, 0);
rb_define_method(rb_cThread, "backtrace", rb_thread_backtrace_m, -1);
rb_define_method(rb_cThread, "backtrace_locations", rb_thread_backtrace_locations_m, -1);
vm_core.h
int safe_level;
int raised_flag;
VALUE last_status; /* $? */
long allocated_objects;
/* passing state */
int state;
(1-1/2)