Class: Mongo::Semaphore Private
- Inherits:
-
Object
- Object
- Mongo::Semaphore
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/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 implementation essentially encapsulating the sample code at ruby-doc.org/stdlib-2.0.0/libdoc/thread/rdoc/ConditionVariable.html.
Instance Method Summary collapse
- #broadcast ⇒ Object private
-
#initialize ⇒ Semaphore
constructor
private
A new instance of Semaphore.
- #signal ⇒ Object private
-
#wait(timeout = nil) ⇒ Object
private
Waits for the semaphore to be signaled up to timeout seconds.
Constructor Details
#initialize ⇒ Semaphore
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 Semaphore.
24 25 26 27 |
# File 'build/ruby-driver-v2.19/lib/mongo/semaphore.rb', line 24 def initialize @lock = Mutex.new @cv = ::ConditionVariable.new 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.
37 38 39 40 41 |
# File 'build/ruby-driver-v2.19/lib/mongo/semaphore.rb', line 37 def broadcast @lock.synchronize do @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.
43 44 45 46 47 |
# File 'build/ruby-driver-v2.19/lib/mongo/semaphore.rb', line 43 def signal @lock.synchronize do @cv.signal end end |
#wait(timeout = nil) ⇒ 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.
Waits for the semaphore to be signaled up to timeout seconds. If semaphore is not signaled, returns after timeout seconds.
31 32 33 34 35 |
# File 'build/ruby-driver-v2.19/lib/mongo/semaphore.rb', line 31 def wait(timeout = nil) @lock.synchronize do @cv.wait(@lock, timeout) end end |