Class: Mongo::Semaphore Private

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeSemaphore

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 'lib/mongo/semaphore.rb', line 24

def initialize
  @lock = Mutex.new
  @cv = ::ConditionVariable.new
end

Instance Method Details

#broadcastObject

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 'lib/mongo/semaphore.rb', line 37

def broadcast
  @lock.synchronize do
    @cv.broadcast
  end
end

#signalObject

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 '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 'lib/mongo/semaphore.rb', line 31

def wait(timeout = nil)
  @lock.synchronize do
    @cv.wait(@lock, timeout)
  end
end