Class: Mongo::Semaphore Private
- Inherits:
-
Object
- Object
- Mongo::Semaphore
- Defined in:
- 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.
21 22 23 24 |
# File 'lib/mongo/semaphore.rb', line 21 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.
34 35 36 37 38 |
# File 'lib/mongo/semaphore.rb', line 34 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.
40 41 42 43 44 |
# File 'lib/mongo/semaphore.rb', line 40 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.
28 29 30 31 32 |
# File 'lib/mongo/semaphore.rb', line 28 def wait(timeout = nil) @lock.synchronize do @cv.wait(@lock, timeout) end end |