aboutsummaryrefslogtreecommitdiff
path: root/build2/scheduler
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-02-09 20:23:47 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-02-13 12:42:42 +0200
commit107357ca4d02341810f47dee20df034e9c4574e0 (patch)
tree8a276d03c9f0a38f172d850fac033aa83ee2d454 /build2/scheduler
parent29e92840c5eb6e56e047d1b0d2b80db66e9eaae5 (diff)
Various scheduler fixes, enhancements, and tuning
While the task_ flags logic is hairy, it seems to work.
Diffstat (limited to 'build2/scheduler')
-rw-r--r--build2/scheduler23
1 files changed, 17 insertions, 6 deletions
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