From c08b0ce638361a84d3648aacd4ffbd0da6c357d8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 7 Aug 2019 06:19:51 +0200 Subject: Distinguish between internal/external wait deactivation in scheduler This turns out to be necessary for the deadlock detection to work properly. --- libbuild2/scheduler.hxx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'libbuild2/scheduler.hxx') diff --git a/libbuild2/scheduler.hxx b/libbuild2/scheduler.hxx index af1deba..7ceb239 100644 --- a/libbuild2/scheduler.hxx +++ b/libbuild2/scheduler.hxx @@ -132,15 +132,19 @@ namespace build2 resume (const atomic_count& task_count); // An active thread that is about to wait for potentially significant time - // on something other than task_count (e.g., mutex, condition variable) - // should deactivate itself with the scheduler and then reactivate once - // done waiting. + // on something other than task_count (e.g., mutex, condition variable, + // timer, etc) should deactivate itself with the scheduler and then + // reactivate once done waiting. + // + // The external flag indicates whether the wait is for an event external + // to the scheduler, that is, triggered by something other than one of the + // threads managed by the scheduler. // void - deactivate (); + deactivate (bool external); void - activate (bool collision = false); + activate (bool external, bool = false); // Sleep for the specified duration, deactivating the thread before going // to sleep and re-activating it after waking up (which means this @@ -413,8 +417,9 @@ namespace build2 size_t helpers_ = 0; // Number of helper threads created so far. - // Every thread that we manage must be accounted for in one of these - // counters. And their sum should equal (init_active + helpers). + // Every thread that we manage (except for the special deadlock monitor) + // must be accounted for in one of these counters. And their sum should + // equal (init_active + helpers). // size_t active_ = 0; // Active master threads executing a task. size_t idle_ = 0; // Idle helper threads waiting for a task. @@ -422,6 +427,10 @@ namespace build2 size_t ready_ = 0; // Ready master thread waiting to become active. size_t starting_ = 0; // Helper threads starting up. + // Number of waiting threads that are waiting for an external event. + // + size_t external_ = 0; + // Original values (as specified during startup) that can be altered via // tuning. // -- cgit v1.1