summaryrefslogtreecommitdiff
path: root/lib/weakref.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-07-10 04:49:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-07-10 04:49:24 +0000
commitc67a74570dd056569763f5015e0aafa7d454fca7 (patch)
treef1dda39296b6911752cd4b6446a21f2e54ff68e1 /lib/weakref.rb
parent3043170b14875ce53f3a951d665279b12c2c63a8 (diff)
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/weakref.rb')
-rw-r--r--lib/weakref.rb28
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/weakref.rb b/lib/weakref.rb
index 18b530f..a6519e6 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -19,18 +19,24 @@ class WeakRef<Delegator
ID_MAP = {} # obj -> [ref,...]
ID_REV_MAP = {} # ref -> obj
ObjectSpace.add_finalizer(lambda{|id|
- rids = ID_MAP[id]
- if rids
- for rid in rids
- ID_REV_MAP[rid] = nil
+ __old_status = Thread.critical
+ Thread.critical = true
+ begin
+ rids = ID_MAP[id]
+ if rids
+ for rid in rids
+ ID_REV_MAP[rid] = nil
+ end
+ ID_MAP[id] = nil
end
- ID_MAP[id] = nil
- end
- rid = ID_REV_MAP[id]
- if rid
- ID_REV_MAP[id] = nil
- ID_MAP[rid].delete(id)
- ID_MAP[rid] = nil if ID_MAP[rid].empty?
+ rid = ID_REV_MAP[id]
+ if rid
+ ID_REV_MAP[id] = nil
+ ID_MAP[rid].delete(id)
+ ID_MAP[rid] = nil if ID_MAP[rid].empty?
+ end
+ ensure
+ Thread.critical = __old_status
end
})