Skip to content

Commit

Permalink
Use WeakRef.__object__ in ThreadGroup to get the object once.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Sep 25, 2011
1 parent 6c7328f commit ccc21cc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions kernel/common/thread_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ def add(thread)
end
thread.add_to_group self

@threads.delete_if { |w| !w.weakref_alive? or !w.object.alive? }
@threads.delete_if do |w|
obj = w.__object__
!(obj and obj.alive?)
end

@threads << WeakRef.new(thread)
self
end

def remove(thread)
@threads.delete_if { |w| !w.weakref_alive? or !w.object.alive? or w.object == thread }
@threads.delete_if { |w| w.__object__ == thread }
end

def list
list = []
@threads.each { |w| list << w.object if w.weakref_alive? and w.object.alive? }
@threads.each do |w|
obj = w.__object__
list << obj if obj and obj.alive?
end
list
end
end

0 comments on commit ccc21cc

Please sign in to comment.