schoefmax-tlattr_accessors 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,11 +33,11 @@ module ThreadLocalAccessors
33
33
 
34
34
  def #{name}=(val)
35
35
  #{ivar} = Hash.new #{'{|h, k| h[k] = val}' if first_is_default} unless #{ivar}
36
- unless #{ivar}.has_key?(Thread.current)
37
- finalize = Thread.current.object_id # required for JRuby compatibility
38
- ObjectSpace.define_finalizer(Thread.current, lambda { #{ivar}.delete(finalize) })
36
+ thread_id = Thread.current.object_id
37
+ unless #{ivar}.has_key?(thread_id)
38
+ ObjectSpace.define_finalizer(Thread.current, lambda { #{ivar}.delete(thread_id) })
39
39
  end
40
- #{ivar}[Thread.current.object_id] = val
40
+ #{ivar}[thread_id] = val
41
41
  end
42
42
  }, __FILE__, __LINE__
43
43
  end
@@ -60,7 +60,6 @@ describe ThreadLocalAccessors do
60
60
  x.bar.should == 2
61
61
  end
62
62
 
63
- # This will epically FAIL under JRuby, as JRuby doesn't support finalizers
64
63
  it 'should not leak memory' do
65
64
  x = Foo.new
66
65
  n = 6000
@@ -74,5 +73,15 @@ describe ThreadLocalAccessors do
74
73
  hash.size.should < (n / 2) # it should be a lot lower than n!
75
74
  end
76
75
 
76
+ it 'should define only one finalizer per thread' do
77
+ ObjectSpace.should_receive(:define_finalizer).exactly(:twice)
78
+ x = Foo.new
79
+ 2.times do
80
+ Thread.new do
81
+ 10.times { x.foo = "bar" }
82
+ end.join
83
+ end
84
+ end
85
+
77
86
  end
78
87
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tlattr_accessors}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
  s.authors = ["Maximilian Sch\303\266fmann"]
7
7
  s.date = %q{2009-03-10}
8
8
  s.description = "thread-local accessors for your classes"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schoefmax-tlattr_accessors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Maximilian Sch\xC3\xB6fmann"