class Rake::Parallel::Driver

  1. lib/rake/parallel.rb
Parent: Parallel

Methods

Public Reader

  1. tasks

Public Class

  1. new

Public Instance

  1. invoke
  2. compute

Attributes

tasks [R]

Tasks collected during the dry-run phase.

Public Class methods

new ()
[show source]
    # File lib/rake/parallel.rb, line 27
27:       def initialize
28:         @tasks = Hash.new
29:         @mutex = Mutex.new
30:       end

Public Instance methods

invoke (threads, task, *task_args)

Top-level parallel invocation.

Called from Task#invoke (routed through Task#invoke_parallel).

[show source]
    # File lib/rake/parallel.rb, line 37
37:       def invoke(threads, task, *task_args)
38:         if @mutex.try_lock
39:           begin
40:             @tasks.clear
41: 
42:             # dry run task collector
43:             task.invoke_serial(*task_args)
44: 
45:             if @tasks.has_key? task
46:               # hand it off to comp_tree
47:               compute(task, threads)
48:             end
49:           ensure
50:             @mutex.unlock
51:           end
52:         else
53:           raise InvokeInsideInvoke
54:         end
55:       end
compute (root_task, threads)

Build and run the computation tree.

Called from Parallel::Driver#invoke.

[show source]
    # File lib/rake/parallel.rb, line 62
62:       def compute(root_task, threads)
63:         CompTree.build do |driver|
64:           @tasks.each_pair do |task, (task_args, prereqs)|
65:             needed_prereq_names = []
66: 
67:             prereqs.each do |prereq|
68:               # if a prereq is not needed then it didn't get into @tasks
69:               if @tasks.has_key? prereq
70:                 needed_prereq_names << prereq.name
71:               end
72:             end
73: 
74:             # define a computation node which executes the task
75:             driver.define(task.name, *needed_prereq_names) {
76:               task.execute(task_args)
77:             }
78:           end
79: 
80:           # punch it
81:           driver.compute(root_task.name, threads)
82:         end
83:       end