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



21
22
23
24
# File 'lib/mongo/semaphore.rb', line 21

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.



34
35
36
37
38
# File 'lib/mongo/semaphore.rb', line 34

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.



40
41
42
43
44
# File 'lib/mongo/semaphore.rb', line 40

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

#wait(timeout) ⇒ 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)
  @lock.synchronize do
    @cv.wait(@lock, timeout)
  end
end