From 107357ca4d02341810f47dee20df034e9c4574e0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Feb 2017 20:23:47 +0200 Subject: Various scheduler fixes, enhancements, and tuning While the task_ flags logic is hairy, it seems to work. --- build2/scheduler | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'build2/scheduler') diff --git a/build2/scheduler b/build2/scheduler index 7447021..1ce98e8 100644 --- a/build2/scheduler +++ b/build2/scheduler @@ -98,13 +98,20 @@ namespace build2 // count starts before/during async() calls, then it must be "gated" with // an alternative (lower) start count. // + // Finally, if waiting on someone else's start count, it is most likely + // unsafe (from the deadlock's point of view) to continue working through + // our own queue (i.e., we may block waiting on a task that has been + // queued before us which in turn may end up waiting on "us"). + // void - wait (size_t start_count, const atomic_count& task_count); + wait (size_t start_count, + const atomic_count& task_count, + bool work_queue = true); void - wait (const atomic_count& task_count) + wait (const atomic_count& task_count, bool work_queue = true) { - wait (0, task_count); + wait (0, task_count, work_queue); } // Resume threads waiting on this task count. @@ -161,6 +168,11 @@ namespace build2 void tune (size_t max_active); + // Return true if the scheduler is running serial. + // + bool + serial () const {return max_active_ == 1;} + // Wait for all the helper threads to terminate. Throw system_error on // failure. Note that the initially active threads are not waited for. // Return scheduling statistics. @@ -338,8 +350,7 @@ namespace build2 // // Each queue has its own mutex. If the task_ flag above is true then // there *might* be a task in one of the queues. If it is false, then - // it means there are either no tasks or someone is busy working on - // them. + // it means there are definitely no tasks. // // For now we only support trivially-destructible tasks. // @@ -378,7 +389,7 @@ namespace build2 std::mutex mutex; bool shutdown = false; - size_t stat_full = 0; // Number of times pop() returned NULL. + size_t stat_full = 0; // Number of times push() returned NULL. // Our task queue is circular with head being the index of the first // element and tail -- of the last. Since this makes the empty and one -- cgit v1.1