Merge pull request #84 from jonisavo/remove-thread-critical

Remove all Thread.critical usage from BitmapCache
This commit is contained in:
Maruno17
2021-01-18 22:04:44 +00:00
committed by GitHub

View File

@@ -41,15 +41,10 @@ end
class WeakRef class WeakRef
@@id_map = {} @@id_map = {}
@@id_rev_map = {} @@id_rev_map = {}
@@final = lambda { |id| @@final = lambda do |id|
old_thread_status = Thread.critical
Thread.critical = true
begin
rids = @@id_map[id] rids = @@id_map[id]
if rids if rids
for rid in rids rids.each { |rid| @@id_rev_map.delete(rid) }
@@id_rev_map.delete(rid)
end
@@id_map.delete(id) @@id_map.delete(id)
end end
rid = @@id_rev_map[id] rid = @@id_rev_map[id]
@@ -58,10 +53,7 @@ class WeakRef
@@id_map[rid].delete(id) @@id_map[rid].delete(id)
@@id_map.delete(rid) if @@id_map[rid].empty? @@id_map.delete(rid) if @@id_map[rid].empty?
end end
ensure
Thread.critical = old_thread_status
end end
}
# Create a new WeakRef from +orig+. # Create a new WeakRef from +orig+.
def initialize(orig) def initialize(orig)
@@ -81,17 +73,11 @@ class WeakRef
def __setobj__(obj) def __setobj__(obj)
@__id = obj.__id__ @__id = obj.__id__
old_thread_status = Thread.critical
begin
Thread.critical = true
unless @@id_rev_map.key?(self) unless @@id_rev_map.key?(self)
ObjectSpace.define_finalizer obj, @@final ObjectSpace.define_finalizer obj, @@final
ObjectSpace.define_finalizer self, @@final ObjectSpace.define_finalizer self, @@final
end end
@@id_map[@__id] = [] unless @@id_map[@__id] @@id_map[@__id] = [] unless @@id_map[@__id]
ensure
Thread.critical = old_thread_status
end
@@id_map[@__id].push self.__id__ @@id_map[@__id].push self.__id__
@@id_rev_map[self.__id__] = @__id @@id_rev_map[self.__id__] = @__id
end end