lib/zk/pool.rb in zk-1.4.2 vs lib/zk/pool.rb in zk-1.5.0

- old
+ new

@@ -89,10 +89,17 @@ # free any waiting @checkin_cond.broadcast end end + # @private + def wait_until_closed + @mutex.synchronize do + @checkin_cond.wait_until { @state == :closed } + end + end + # yields next available connection to the block # # raises PoolIsShuttingDownException immediately if close_all! has been # called on this pool def with_connection @@ -137,11 +144,11 @@ def synchronize @mutex.synchronize { yield } end def assert_open! - raise Exceptions::PoolIsShuttingDownException unless open? + raise Exceptions::PoolIsShuttingDownException, "pool is shutting down" unless open? end end # Base # like a Simple pool but has high/low watermarks, and can grow dynamically as needed @@ -193,22 +200,23 @@ return end @pool << connection - @checkin_cond.signal + @checkin_cond.broadcast end end # number of threads waiting for connections def count_waiters #:nodoc: @mutex.synchronize { @count_waiters } end def checkout(blocking=true) raise ArgumentError, "checkout does not take a block, use .with_connection" if block_given? - @mutex.synchronize do + @mutex.lock + begin while true assert_open! if @pool.length > 0 cnx = @pool.shift @@ -234,10 +242,12 @@ @checkin_cond.wait_while { @pool.empty? and open? } next else return false end - end # while + end # while + ensure + @mutex.unlock rescue nil end end # @private def can_grow_pool?