From 88379eedeae654391711d8cdda17dfc2be6367ef Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 12 May 2021 10:46:21 +0200 Subject: Keep phase locked while working own queue --- libbuild2/scheduler.ixx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'libbuild2/scheduler.ixx') diff --git a/libbuild2/scheduler.ixx b/libbuild2/scheduler.ixx index f9f0f2e..4cf347c 100644 --- a/libbuild2/scheduler.ixx +++ b/libbuild2/scheduler.ixx @@ -3,6 +3,41 @@ namespace build2 { + inline size_t scheduler:: + wait (size_t start_count, const atomic_count& task_count, work_queue wq) + { + // Note that task_count is a synchronization point. + // + size_t tc; + if ((tc = task_count.load (memory_order_acquire)) <= start_count) + return tc; + + if (optional r = wait_impl (start_count, task_count, wq)) + return *r; + + return suspend (start_count, task_count); + } + + template + inline size_t scheduler:: + wait (size_t start_count, + const atomic_count& task_count, + L& lock, + work_queue wq) + { + // Note that task_count is a synchronization point. + // + size_t tc; + if ((tc = task_count.load (memory_order_acquire)) <= start_count) + return tc; + + if (optional r = wait_impl (start_count, task_count, wq)) + return *r; + + lock.unlock (); + return suspend (start_count, task_count); + } + inline scheduler::queue_mark:: queue_mark (scheduler& s) : tq_ (s.queue ()) -- cgit v1.1