From 4322701ecf47e03e4ed6328fc086d9513f2abbc8 Mon Sep 17 00:00:00 2001 From: Fernando Gasperi Jabalera Date: Tue, 14 Jan 2020 12:40:52 -0800 Subject: [PATCH] Use a queue to handle tasks in the RestartScheduler Summary: The RestartScheduler now uses it's own of_list function to build a ProcessPool.TaskGenerator to be able to use a queue as the underlying data structure. Reviewed By: ngorogiannis Differential Revision: D19390055 fbshipit-source-id: d57b493b7 --- infer/src/backend/RestartScheduler.ml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/infer/src/backend/RestartScheduler.ml b/infer/src/backend/RestartScheduler.ml index d557db215..9f373f97a 100644 --- a/infer/src/backend/RestartScheduler.ml +++ b/infer/src/backend/RestartScheduler.ml @@ -6,13 +6,23 @@ *) open! IStd +let of_list (lst : 'a list) : 'a ProcessPool.TaskGenerator.t = + let content = Queue.of_list lst in + let length = ref (Queue.length content) in + let remaining_tasks () = !length in + let is_empty () = Queue.is_empty content in + let finished _finished_item = decr length in + let next () = Queue.dequeue content in + {remaining_tasks; is_empty; finished; next} + + (** This behaves exactly the same as the FileScheduler so far. The goal is that it will use a work queue and proc locking to avoid repeating work and hopefully get some in process cache hits. *) let make sources = let gen = List.rev_map sources ~f:(fun sf -> SchedulerTypes.File sf) |> List.permute ~random_state:(Random.State.make (Array.create ~len:1 0)) - |> ProcessPool.TaskGenerator.of_list + |> of_list in let next x = let res = gen.next x in