From bcb2a89e111a918a48a132a2a29e0c26d724591d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 10 Feb 2017 07:56:33 +0200 Subject: Redo scheduler task flag as atomic counter Makes for simpler code and also seems to perform better. --- build2/scheduler.txx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'build2/scheduler.txx') diff --git a/build2/scheduler.txx b/build2/scheduler.txx index d5e9afa..f53c044 100644 --- a/build2/scheduler.txx +++ b/build2/scheduler.txx @@ -36,7 +36,7 @@ namespace build2 if ((td = push (*tq)) != nullptr) { - // Package the task. + // Package the task (under lock). // new (&td->data) task { &task_count, @@ -63,13 +63,16 @@ namespace build2 // task_count.fetch_add (1, std::memory_order_release); - lock l (mutex_); - task_ = true; - - // If there is a spare active thread, wake up (or create) the helper. + // If there is a spare active thread, wake up (or create) the helper + // (unless someone already snatched it). // - if (active_ < max_active_) - activate_helper (l); + if (queued_task_count_ != 0) + { + lock l (mutex_); + + if (active_ < max_active_) + activate_helper (l); + } return true; } -- cgit v1.1