diff --git a/lib/ceedling/par_map.rb b/lib/ceedling/par_map.rb index 98198a2c..23723601 100644 --- a/lib/ceedling/par_map.rb +++ b/lib/ceedling/par_map.rb @@ -1,9 +1,15 @@ - def par_map(n, things, &block) + if (things.length <= 1) + yield things.pop() if not things.empty? + return + end + queue = Queue.new things.each { |thing| queue << thing } - threads = (1..n).collect do + + num_threads = [n, things.length].min() + threads = (1..num_threads).collect do Thread.new do begin while true diff --git a/lib/ceedling/preprocessinator_helper.rb b/lib/ceedling/preprocessinator_helper.rb index 4bbda67f..e91d3e63 100644 --- a/lib/ceedling/preprocessinator_helper.rb +++ b/lib/ceedling/preprocessinator_helper.rb @@ -1,3 +1,4 @@ +require 'ceedling/par_map' class PreprocessinatorHelper @@ -43,7 +44,12 @@ def preprocess_files_smartly(file_list, preprocess_file_proc) if (@configurator.project_use_deep_dependencies) @task_invoker.invoke_test_preprocessed_files(file_list) else - file_list.each { |file| preprocess_file_proc.call( yield(file) ) } + found_files = Array.new + file_list.each { |file| found_files << yield(file) } + + par_map(PROJECT_COMPILE_THREADS, found_files) do |file| + preprocess_file_proc.call(file) + end end end