patch2.diff

Masaki Matsushita, 09/23/2011 11:43 PM

Download (1.55 KB)

View differences:

lib/weakref.rb
28 28
  @@id_rev_map =  {}            # ref -> obj
29 29
  @@mutex = Mutex.new
30 30
  @@final = lambda {|id|
31
    @@mutex.synchronize {
32
      rids = @@id_map[id]
33
      if rids
34
        for rid in rids
35
          @@id_rev_map.delete(rid)
31
    GC.disable
32
    begin
33
      @@mutex.synchronize {
34
        rids = @@id_map[id]
35
        if rids
36
          for rid in rids
37
            @@id_rev_map.delete(rid)
38
          end
39
          @@id_map.delete(id)
40
        end
41
        rid = @@id_rev_map[id]
42
        if rid
43
          @@id_rev_map.delete(id)
44
          @@id_map[rid].delete(id)
45
          @@id_map.delete(rid) if @@id_map[rid].empty?
36 46
        end
37
        @@id_map.delete(id)
38
      end
39
      rid = @@id_rev_map[id]
40
      if rid
41
        @@id_rev_map.delete(id)
42
        @@id_map[rid].delete(id)
43
        @@id_map.delete(rid) if @@id_map[rid].empty?
44
      end
45
    }
47
      }
48
    ensure
49
      GC.enable
50
    end
46 51
  }
47 52

  
48 53
  ##
......
52 57
    @__id = orig.object_id
53 58
    ObjectSpace.define_finalizer orig, @@final
54 59
    ObjectSpace.define_finalizer self, @@final
55
    @@mutex.synchronize {
56
      @@id_map[@__id] = [] unless @@id_map[@__id]
57
    }
60
    GC.disable
61
    begin
62
      @@mutex.synchronize {
63
        @@id_map[@__id] = [] unless @@id_map[@__id]
64
      }
65
    ensure
66
      GC.enable
67
    end
58 68
    @@id_map[@__id].push self.object_id
59 69
    @@id_rev_map[self.object_id] = @__id
60 70
    super