Class: LightIO::Library::Thread::ConditionVariable

Inherits:
Object
  • Object
show all
Extended by:
Base::MockMethods
Defined in:
lib/lightio/library/thread.rb

Instance Method Summary collapse

Constructor Details

#initializeConditionVariable

Returns a new instance of ConditionVariable.



291
292
293
# File 'lib/lightio/library/thread.rb', line 291

def initialize
  @queue = LightIO::Library::Queue.new
end

Instance Method Details

#broadcastObject



296
297
298
299
# File 'lib/lightio/library/thread.rb', line 296

def broadcast
  signal until @queue.num_waiting == 0
  self
end

#signalObject



301
302
303
304
# File 'lib/lightio/library/thread.rb', line 301

def signal
  @queue << true unless @queue.num_waiting == 0
  self
end

#wait(mutex, timeout = nil) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/lightio/library/thread.rb', line 306

def wait(mutex, timeout=nil)
  mutex.unlock
  begin
    LightIO::Library::Timeout.timeout(timeout) do
      @queue.pop
    end
  rescue Timeout::Error
    nil
  end
  mutex.lock
  self
end