Bug #5350 » patch2.diff
| lib/weakref.rb | ||
|---|---|---|
|
@@id_rev_map = {} # ref -> obj
|
||
|
@@mutex = Mutex.new
|
||
|
@@final = lambda {|id|
|
||
|
@@mutex.synchronize {
|
||
|
rids = @@id_map[id]
|
||
|
if rids
|
||
|
for rid in rids
|
||
|
@@id_rev_map.delete(rid)
|
||
|
GC.disable
|
||
|
begin
|
||
|
@@mutex.synchronize {
|
||
|
rids = @@id_map[id]
|
||
|
if rids
|
||
|
for rid in rids
|
||
|
@@id_rev_map.delete(rid)
|
||
|
end
|
||
|
@@id_map.delete(id)
|
||
|
end
|
||
|
rid = @@id_rev_map[id]
|
||
|
if rid
|
||
|
@@id_rev_map.delete(id)
|
||
|
@@id_map[rid].delete(id)
|
||
|
@@id_map.delete(rid) if @@id_map[rid].empty?
|
||
|
end
|
||
|
@@id_map.delete(id)
|
||
|
end
|
||
|
rid = @@id_rev_map[id]
|
||
|
if rid
|
||
|
@@id_rev_map.delete(id)
|
||
|
@@id_map[rid].delete(id)
|
||
|
@@id_map.delete(rid) if @@id_map[rid].empty?
|
||
|
end
|
||
|
}
|
||
|
}
|
||
|
ensure
|
||
|
GC.enable
|
||
|
end
|
||
|
}
|
||
|
##
|
||
| ... | ... | |
|
@__id = orig.object_id
|
||
|
ObjectSpace.define_finalizer orig, @@final
|
||
|
ObjectSpace.define_finalizer self, @@final
|
||
|
@@mutex.synchronize {
|
||
|
@@id_map[@__id] = [] unless @@id_map[@__id]
|
||
|
}
|
||
|
GC.disable
|
||
|
begin
|
||
|
@@mutex.synchronize {
|
||
|
@@id_map[@__id] = [] unless @@id_map[@__id]
|
||
|
}
|
||
|
ensure
|
||
|
GC.enable
|
||
|
end
|
||
|
@@id_map[@__id].push self.object_id
|
||
|
@@id_rev_map[self.object_id] = @__id
|
||
|
super
|
||
- « Previous
- 1
- 2
- 3
- Next »