Sha256: 785b4e6cabbad9e574158b74943f10187480a7c3e50e0837eabf698ec2d1e238

Contents?: true

Size: 706 Bytes

Versions: 6

Compression:

Stored size: 706 Bytes

Contents

module Gtk3App
module Slot
  using Rafini::Array

  def self.dbm
    SDBM.open(CONFIG[:SlotsDBM]){|db|yield(db)}
  end

  def self.numbers
    1.upto(CONFIG[:Slots]){|n|yield(n.to_s)}
  end

  def self.get
    Slot.dbm do |db|
      Slot.numbers do |slot|
        unless db[slot]
          db[slot]=$$.to_s
          return slot.to_i
        end
      end
    end
    return nil
  end

  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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gtk3app-3.0.0 lib/gtk3app/slot.rb
gtk3app-2.1.1 lib/gtk3app/slot.rb
gtk3app-2.1.0 lib/gtk3app/slot.rb
gtk3app-2.0.2 lib/gtk3app/slot.rb
gtk3app-2.0.1 lib/gtk3app/slot.rb
gtk3app-2.0.0 lib/gtk3app/slot.rb