class MessagePack::Factory::Pool::AbstractPool
def checkin(member)
def checkin(member) # If the pool is already full, we simply drop the extra member. # This is because contrary to a connection pool, creating an extra instance # is extremely unlikely to cause some kind of resource exhaustion. # # We could cycle the members (keep the newer one) but first It's more work and second # the older member might have been created pre-fork, so it might be at least partially # in shared memory. if member && @members.size < @size member.reset @members << member end end
def checkin(member)
def checkin(member) @mutex.synchronize do if member && @members.size < @size member.reset @members << member end end end
def checkout
def checkout @members.pop || @new_member.call end
def checkout
def checkout @mutex.synchronize { @members.pop } || @new_member.call end
def initialize(size, &block)
def initialize(size, &block) @size = size @new_member = block @members = [] end
def initialize(size, &block)
def initialize(size, &block) @size = size @new_member = block @members = [] @mutex = Mutex.new end