123456789_123456789_123456789_123456789_123456789_

Class: Mongo::DistinguishingSemaphore Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/distinguishing_semaphore.rb

Overview

This is a semaphore that distinguishes waits ending due to the timeout being reached from waits ending due to the semaphore being signaled.

Class Method Summary

Instance Method Summary

Instance Method Details

#broadcast

[ GitHub ]

  
# File 'lib/mongo/distinguishing_semaphore.rb', line 44

def broadcast
  @lock.synchronize do
    @queue.push(true)
    @cv.broadcast
  end
end

#signal

[ GitHub ]

  
# File 'lib/mongo/distinguishing_semaphore.rb', line 51

def signal
  @lock.synchronize do
    @queue.push(true)
    @cv.signal
  end
end

#wait(timeout = nil) ⇒ true | false

Waits for the semaphore to be signaled up to timeout seconds. If semaphore is not signaled, returns after timeout seconds.

Returns:

  • (true | false)

    true if semaphore was signaled, false if timeout was reached.

[ GitHub ]

  
# File 'lib/mongo/distinguishing_semaphore.rb', line 35

def wait(timeout = nil)
  @lock.synchronize do
    @cv.wait(@lock, timeout)
    (!@queue.empty?).tap do
      @queue.clear
    end
  end
end