Class: Rake::Jobs
- Inherits:
-
Object
- Object
- Rake::Jobs
- Defined in:
- lib/cxxproject/ext/rake.rb
Instance Method Summary collapse
- #get_next_or_nil ⇒ Object
-
#initialize(jobs, max, &block) ⇒ Jobs
constructor
A new instance of Jobs.
- #join ⇒ Object
- #mutex ⇒ Object
Constructor Details
#initialize(jobs, max, &block) ⇒ Jobs
Returns a new instance of Jobs.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cxxproject/ext/rake.rb', line 80 def initialize(jobs, max, &block) nr_of_threads = [max, jobs.length].min @jobs = jobs @threads = [] nr_of_threads.times do @threads << Thread.new do block.call(self) end end end |
Instance Method Details
#get_next_or_nil ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/cxxproject/ext/rake.rb', line 91 def get_next_or_nil the_next = nil mutex.synchronize { the_next = @jobs.shift } the_next end |
#join ⇒ Object
98 99 100 |
# File 'lib/cxxproject/ext/rake.rb', line 98 def join @threads.each{|t| while not t.join(2) do end} end |
#mutex ⇒ Object
101 102 103 |
# File 'lib/cxxproject/ext/rake.rb', line 101 def mutex @mutex ||= Mutex.new end |