lib/glue/pool.rb in glue-0.20.0 vs lib/glue/pool.rb in glue-0.21.0

- old
+ new

@@ -1,8 +1,8 @@ # * George Moschovitis <gm@navel.gr> # (c) 2004-2005 Navel, all rights reserved. -# $Id: pool.rb 1 2005-04-11 11:04:30Z gmosx $ +# $Id: pool.rb 182 2005-07-22 10:07:50Z gmosx $ require 'thread' require 'monitor' module Glue @@ -11,50 +11,50 @@ # safe stack. Exclusive locking is needed both for push and pop. # # INVESTIGATE: Could use the SizedQueue/Queue. class Pool < Array - include MonitorMixin - - def initialize - super - @cv = new_cond() - end + include MonitorMixin + + def initialize + super + @cv = new_cond() + end - # Add, restore an object to the pool. - - def push(obj) - synchronize do - super - @cv.signal() - end - end - - # Obtain an object from the pool. - - def pop - synchronize do - @cv.wait_while { empty? } - super - end - end + # Add, restore an object to the pool. + + def push(obj) + synchronize do + super + @cv.signal() + end + end + + # Obtain an object from the pool. + + def pop + synchronize do + @cv.wait_while { empty? } + super + end + end - # Obtains an object, passes it to a block for processing - # and restores it to the pool. + # Obtains an object, passes it to a block for processing + # and restores it to the pool. - def obtain - result = nil - - begin - obj = pop() + def obtain + result = nil + + begin + obj = pop() - result = yield(obj) - ensure - push(obj) - end + result = yield(obj) + ensure + push(obj) + end - return result - end - + return result + end + end end