Class: Rake::Parallel::Driver
- Inherits:
-
Object
- Object
- Rake::Parallel::Driver
- Defined in:
- lib/rake/parallel.rb
Instance Attribute Summary collapse
-
#tasks ⇒ Object
readonly
Tasks collected during the dry-run phase.
Instance Method Summary collapse
-
#compute(root_task, threads) ⇒ Object
Build and run the computation tree.
-
#initialize ⇒ Driver
constructor
A new instance of Driver.
-
#invoke(threads, task, *task_args) ⇒ Object
Top-level parallel invocation.
Constructor Details
#initialize ⇒ Driver
Returns a new instance of Driver.
27 28 29 30 |
# File 'lib/rake/parallel.rb', line 27 def initialize @tasks = Hash.new @mutex = Mutex.new end |
Instance Attribute Details
#tasks ⇒ Object (readonly)
Tasks collected during the dry-run phase.
25 26 27 |
# File 'lib/rake/parallel.rb', line 25 def tasks @tasks end |
Instance Method Details
#compute(root_task, threads) ⇒ Object
Build and run the computation tree.
Called from Parallel::Driver#invoke.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rake/parallel.rb', line 62 def compute(root_task, threads) CompTree.build do |driver| @tasks.each_pair do |task, (task_args, prereqs)| needed_prereq_names = [] prereqs.each do |prereq| # if a prereq is not needed then it didn't get into @tasks if @tasks.has_key? prereq needed_prereq_names << prereq.name end end # define a computation node which executes the task driver.define(task.name, *needed_prereq_names) { task.execute(task_args) } end # punch it driver.compute(root_task.name, threads) end end |
#invoke(threads, task, *task_args) ⇒ Object
Top-level parallel invocation.
Called from Task#invoke (routed through Task#invoke_parallel).
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rake/parallel.rb', line 37 def invoke(threads, task, *task_args) if @mutex.try_lock begin @tasks.clear # dry run task collector task.invoke_serial(*task_args) if @tasks.has_key? task # hand it off to comp_tree compute(task, threads) end ensure @mutex.unlock end else raise InvokeInsideInvoke end end |