module OMGF::Pool
Public Instance Methods
pool_init(mg_opts)
click to toggle source
TODO: backport these improvements to MogileFS::Pool (but break compat?)
# File lib/omgf/pool.rb, line 8 def pool_init(mg_opts) @mg_opts = mg_opts @pool = [] @lock = Mutex.new end
pool_use(domain) { |mg| ... }
click to toggle source
# File lib/omgf/pool.rb, line 14 def pool_use(domain) # Array#pop is faster than Queue#pop since Queue#pop shifts off # the array internally, and taking the last element off the end is faster. mg = @lock.synchronize { @pool.pop || MogileFS::MogileFS.new(@mg_opts) } mg.domain = domain rv = yield mg @lock.synchronize do if @pool.size < 3 @pool << mg mg = nil # prevent shutdown end end rv ensure # shutdown if we didn't return to the pool if mg mg.backend.shutdown rescue nil end end