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
- .new ⇒ DistinguishingSemaphore constructor Internal use only
Instance Method Summary
- #broadcast Internal use only
- #signal Internal use only
-
#wait(timeout = nil) ⇒ true | false
Internal use only
Waits for the semaphore to be signaled up to timeout seconds.
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.
# 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