Project

General

Profile

Bug #5350 » patch2.diff

Glass_saga (Masaki Matsushita), 09/23/2011 11:43 PM

View differences:

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
(3-3/3)