Class: ExecJS::PCRuntime::Semaphore

Inherits:
Object
  • Object
show all
Defined in:
lib/execjs/pcruntime/context_process_runtime.rb

Overview

Semaphore implemented with Thread::Queue since faster than Concurrent::Semaphore and Mutex+ConditionVariable

Instance Method Summary collapse

Constructor Details

#initialize(limit) ⇒ Semaphore

Returns a new instance of Semaphore.

Parameters:

  • limit (Integer)


315
316
317
318
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 315

def initialize(limit)
  @queue = Thread::Queue.new
  limit.times { @queue.push nil }
end

Instance Method Details

#acquireObject

acquires 1 of permits from this semaphore, blocking until be available.



321
322
323
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 321

def acquire
  @queue.pop
end

#releaseObject

releases 1 of permits



326
327
328
# File 'lib/execjs/pcruntime/context_process_runtime.rb', line 326

def release
  @queue.push nil
end