Project

General

Profile

Feature #11098 ยป thread-local.patch

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

View differences:

gc.c
1741 1741
#endif
1742 1742

  
1743 1743
    objspace->total_allocated_objects++;
1744

  
1745
    rb_thread_t *th = GET_THREAD();
1746
    th->allocated_objects++;
1747

  
1744 1748
    gc_event_hook(objspace, RUBY_INTERNAL_EVENT_NEWOBJ, obj);
1745 1749
    gc_report(5, objspace, "newobj: %s\n", obj_info(obj));
1746 1750

  
test/ruby/test_thread.rb
1046 1046
      t.new {}
1047 1047
    end
1048 1048
  end
1049

  
1050
  def test_thread_allocated_objects
1051
    count = 0
1052
    t = Thread.new do
1053
      1000.times do
1054
        Object.new
1055
      end
1056
      count += Thread.current.allocated_objects
1057
    end
1058

  
1059
    t.join
1060
    assert_equal 1000, count
1061
  end
1049 1062
end
thread.c
2568 2568
    return group;
2569 2569
}
2570 2570

  
2571
VALUE
2572
rb_thread_allocated_objects(VALUE thread)
2573
{
2574
    rb_thread_t *th;
2575
    GetThreadPtr(thread, th);
2576
    return LONG2NUM(th->allocated_objects);
2577
}
2578

  
2571 2579
static const char *
2572 2580
thread_status_name(rb_thread_t *th)
2573 2581
{
......
5036 5044
    rb_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1);
5037 5045
    rb_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0);
5038 5046
    rb_define_method(rb_cThread, "group", rb_thread_group, 0);
5047
    rb_define_method(rb_cThread, "allocated_objects", rb_thread_allocated_objects, 0);
5039 5048
    rb_define_method(rb_cThread, "backtrace", rb_thread_backtrace_m, -1);
5040 5049
    rb_define_method(rb_cThread, "backtrace_locations", rb_thread_backtrace_locations_m, -1);
5041 5050

  
vm_core.h
598 598
    int safe_level;
599 599
    int raised_flag;
600 600
    VALUE last_status; /* $? */
601
    long allocated_objects;
601 602

  
602 603
    /* passing state */
603 604
    int state;