lib/zk/locker/shared_locker.rb in zk-1.4.2 vs lib/zk/locker/shared_locker.rb in zk-1.5.0

- old
+ new

@@ -11,13 +11,11 @@ create_lock_path!(SHARED_LOCK_PREFIX) if got_read_lock? @locked = true elsif blocking - in_waiting_status do - block_until_read_lock! - end + block_until_read_lock! else # we didn't get the lock, and we're not gonna wait around for it, so # clean up after ourselves cleanup_lock_path! false @@ -98,16 +96,22 @@ # TODO: make this generic, can either block or non-block def block_until_read_lock! begin path = "#{root_lock_path}/#{next_lowest_write_lock_name}" logger.debug { "SharedLocker#block_until_read_lock! path=#{path.inspect}" } - @zk.block_until_node_deleted(path) + + synchronize do + @node_deletion_watcher = NodeDeletionWatcher.new(zk, path) + @cond.broadcast + end + + @node_deletion_watcher.block_until_deleted rescue NoWriteLockFoundException # next_lowest_write_lock_name may raise NoWriteLockFoundException, # which means we should not block as we have the lock (there is nothing to wait for) end - @locked = true + synchronize { @locked = true } end end # SharedLocker end # Locker end # ZK