Class: Mongo::DistinguishingSemaphore Private
- Inherits:
-
Object
- Object
- Mongo::DistinguishingSemaphore
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/distinguishing_semaphore.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This is a semaphore that distinguishes waits ending due to the timeout being reached from waits ending due to the semaphore being signaled.
Instance Method Summary collapse
- #broadcast ⇒ Object private
-
#initialize ⇒ DistinguishingSemaphore
constructor
private
A new instance of DistinguishingSemaphore.
- #signal ⇒ Object private
-
#wait(timeout = nil) ⇒ true | false
private
Waits for the semaphore to be signaled up to timeout seconds.
Constructor Details
#initialize ⇒ DistinguishingSemaphore
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of DistinguishingSemaphore.
24 25 26 27 28 |
# File 'build/ruby-driver-v2.19/lib/mongo/distinguishing_semaphore.rb', line 24 def initialize @lock = Mutex.new @cv = ::ConditionVariable.new @queue = [] end |
Instance Method Details
#broadcast ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 47 48 49 |
# File 'build/ruby-driver-v2.19/lib/mongo/distinguishing_semaphore.rb', line 44 def broadcast @lock.synchronize do @queue.push(true) @cv.broadcast end end |
#signal ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 54 55 56 |
# File 'build/ruby-driver-v2.19/lib/mongo/distinguishing_semaphore.rb', line 51 def signal @lock.synchronize do @queue.push(true) @cv.signal end end |
#wait(timeout = nil) ⇒ true | false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Waits for the semaphore to be signaled up to timeout seconds. If semaphore is not signaled, returns after timeout seconds.
35 36 37 38 39 40 41 42 |
# File 'build/ruby-driver-v2.19/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 |