Project

General

Profile

Feature #11098 ยป thread-local-update.patch

jasonrclark (Jason Clark), 04/27/2016 06:06 PM

View differences:

gc.c
1820 1820
#endif
1821 1821

  
1822 1822
    objspace->total_allocated_objects++;
1823
    GET_THREAD()->allocated_objects++;
1823 1824

  
1824 1825
    gc_report(5, objspace, "newobj: %s\n", obj_info(obj));
1825 1826

  
test/ruby/test_thread.rb
1104 1104
    c = Class.new(Thread) {def initialize() self.name = "foo"; super; end}
1105 1105
    assert_equal("foo", c.new {Thread.current.name}.value)
1106 1106
  end
1107

  
1108
  def test_thread_allocated_objects
1109
    t = Thread.new do
1110
      1000.times do
1111
        Object.new
1112
      end
1113
    end
1114

  
1115
    t.join
1116
    assert_equal 1001, t.allocated_objects
1117
  end
1107 1118
end
thread.c
2616 2616
    return group;
2617 2617
}
2618 2618

  
2619
VALUE
2620
rb_thread_allocated_objects(VALUE thread)
2621
{
2622
    rb_thread_t *th;
2623
    GetThreadPtr(thread, th);
2624
    return LONG2NUM(th->allocated_objects);
2625
}
2626

  
2619 2627
static const char *
2620 2628
thread_status_name(rb_thread_t *th)
2621 2629
{
......
4653 4661
    rb_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1);
4654 4662
    rb_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0);
4655 4663
    rb_define_method(rb_cThread, "group", rb_thread_group, 0);
4664
    rb_define_method(rb_cThread, "allocated_objects", rb_thread_allocated_objects, 0);
4656 4665
    rb_define_method(rb_cThread, "backtrace", rb_thread_backtrace_m, -1);
4657 4666
    rb_define_method(rb_cThread, "backtrace_locations", rb_thread_backtrace_locations_m, -1);
4658 4667

  
vm_core.h
682 682
    int safe_level;
683 683
    int raised_flag;
684 684
    VALUE last_status; /* $? */
685
    uint64_t allocated_objects;
685 686

  
686 687
    /* passing state */
687 688
    int state;