class Daedalus::TaskRunner

Public Class Methods

detect_cpus() click to toggle source
    # File lib/daedalus.rb
911 def self.detect_cpus
912   if RUBY_PLATFORM =~ /windows/
913     return 1
914   else
915     if RUBY_PLATFORM =~ /bsd/
916       key = 'NPROCESSORS_CONF'
917     else
918       key = '_NPROCESSORS_CONF'
919     end
920     count = `getconf #{key} 2>&1`.to_i
921     return 1 if $?.exitstatus != 0
922     return count
923   end
924 end
new(compiler, tasks, max=nil) click to toggle source
    # File lib/daedalus.rb
883 def initialize(compiler, tasks, max=nil)
884   @max = TaskRunner.detect_cpus
885   @tasks = tasks
886   @compiler = compiler
887 
888   calculate_max(max)
889 end

Public Instance Methods

calculate_max(max) click to toggle source
    # File lib/daedalus.rb
891 def calculate_max(max)
892   cpus = TaskRunner.detect_cpus
893 
894   case max
895   when nil # auto
896     case cpus
897     when 1, 2
898       @max = cpus
899     when 4
900       @max = 3
901     else
902       @max = 4
903     end
904   when Fixnum
905     @max = max
906   when "cpu"
907     @max = cpus
908   end
909 end
linear_tasks(tasks) click to toggle source
    # File lib/daedalus.rb
932 def linear_tasks(tasks)
933   tasks.each do |task|
934     task.build @compiler
935   end
936 end
perform_tasks(tasks) click to toggle source
    # File lib/daedalus.rb
938 def perform_tasks(tasks)
939   count = tasks.size
940 
941   puts "Running #{count} tasks using #{@max} parallel threads"
942   start = Time.now
943 
944   queue = Queue.new
945   threads = []
946 
947   @max.times do
948     threads << Thread.new {
949       while true
950         task = queue.pop
951         break unless task
952         task.build @compiler
953       end
954     }
955   end
956 
957   sync = []
958 
959   queue_tasks(queue, tasks, sync)
960 
961   # Kill off the builders
962   threads.each do |t|
963     queue << nil
964   end
965 
966   threads.each do |t|
967     t.join
968   end
969 
970   sync.each do |task|
971     task.build @compiler
972   end
973 
974   puts "Build time: #{Time.now - start} seconds"
975 end
queue_tasks(queue, tasks, sync) click to toggle source
    # File lib/daedalus.rb
977 def queue_tasks(queue, tasks, sync)
978   tasks.each do |task|
979     if task.kind_of? Array
980       queue_tasks queue, task[1..-1], sync
981       sync << task[0]
982     else
983       queue.push task
984     end
985   end
986 end
start() click to toggle source
    # File lib/daedalus.rb
926 def start
927   linear_tasks @tasks.pre
928   perform_tasks @tasks.default
929   linear_tasks @tasks.post
930 end