lib/quack_concurrency/reentrant_mutex.rb
def lock(&block)
      if block_given?  
        lock
        start_depth = @lock_depth
        begin
          yield
        ensure
          ensure_can_unlock
          unless @lock_depth == start_depth
            raise ThreadError, 'Attempt to unlock a ReentrantMutex whose lock depth has been changed since locking it'
          end
          unlock
        end
      else
        super unless owned?
        @lock_depth += 1
        nil
      end
    end
def lock(&block)
      if block_given?  
        lock
        start_depth = @lock_depth
        begin
          yield
        ensure
          ensure_can_unlock
          unless @lock_depth == start_depth
            raise ThreadError, 'Attempt to unlock a ReentrantMutex whose lock depth has been changed since locking it'
          end
          unlock
        end
      else
        super unless owned?
        @lock_depth += 1
        nil
      end
    end
def lock ( & block ) if block_given? lock start_depth = @lock_depth begin yield ensure ensure_can_unlock unless @lock_depth == start_depth raise ThreadError , 'Attempt to unlock a ReentrantMutex whose lock depth has been changed since locking it' end unlock end else super unless owned? @lock_depth += 1 nil end end
Creates a new {ReentrantMutex} concurrency tool.
 @return [ReentrantMutex]
@overload lock
  Obtains a lock, blocking until available.
  It will acquire a lock even if one is already held.
  @return [void]
@overload lock(&block)
  Obtains a lock, runs the block, then releases a lock.
  It will block until a lock is available.
  It will acquire a lock even if one is already held.
  @raise [ThreadError] if not locked by the calling thread when unlocking
  @raise [ThreadError] if not holding the same lock count when unlocking
  @raise [Exception] any exception raised in block
  @yield block to run with the lock
  @return [Object] result of the block
Creates a new { ReentrantMutex } concurrency tool .