lib/gtk3app/slot.rb in gtk3app-1.5.2 vs lib/gtk3app/slot.rb in gtk3app-2.0.0
- old
+ new
@@ -9,14 +9,13 @@
def self.numbers
1.upto(CONFIG[:Slots]){|n|yield(n.to_s)}
end
def self.get
- alive = Sys::ProcTable.ps.select{|p|p.cmdline=~/ruby.*\bgtk3app\b/}.map{|p|p.pid.to_s}.is(true)
Slot.dbm do |db|
Slot.numbers do |slot|
- unless alive[db[slot]]
+ unless db[slot]
db[slot]=$$.to_s
return slot.to_i
end
end
end
@@ -25,7 +24,19 @@
def self.release(slot)
Slot.dbm{|db|db.delete(slot.to_s)}
end
+ def self.gc
+ Thread.new do
+ Slot.dbm do |db|
+ Slot.numbers do |slot|
+ if pid = db[slot]
+ db.delete(slot) unless File.directory?("/proc/#{pid}")
+ end
+ end
+ end
+ end
+ end
+ Slot.gc
end
end