class Bake::Multithread::Jobs

Public Class Methods

decThread() click to toggle source
# File lib/multithread/job.rb, line 15
def self.decThread
  @@semaphore.release
end
incThread() click to toggle source
# File lib/multithread/job.rb, line 12
def self.incThread
  @@semaphore.acquire
end
init_semaphore() click to toggle source
# File lib/multithread/job.rb, line 18
def self.init_semaphore
  @@semaphore = ::Concurrent::MutexSemaphore.new(Bake.options.threads)
end
new(jobs, &block) click to toggle source
# File lib/multithread/job.rb, line 22
def initialize(jobs, &block)
  nr_of_threads = [Bake.options.threads, jobs.length].min
  @jobs = jobs
  @threads = []
  nr_of_threads.times do
    @threads << ::Thread.new(Thread.current[:stdout]) do |outStr|
      Thread.current[:stdout] = outStr
      begin
        Jobs.incThread()
        block.call(self)
      ensure
        Jobs.decThread()
      end
    end
  end
end

Public Instance Methods

failed() click to toggle source
# File lib/multithread/job.rb, line 39
def failed
  @failed ||= false
end
get_next_or_nil() click to toggle source
# File lib/multithread/job.rb, line 46
def get_next_or_nil
  the_next = nil
  mutex.synchronize {
    the_next = @jobs.shift
  }
  the_next
end
join() click to toggle source
# File lib/multithread/job.rb, line 53
def join
  @threads.each{|t| while not t.join(2) do end}
end
mutex() click to toggle source
# File lib/multithread/job.rb, line 56
def mutex
  @mutex ||= Mutex.new
end
set_failed() click to toggle source
# File lib/multithread/job.rb, line 42
def set_failed
  @failed = true
end