diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-04-08 14:27:25 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-04-08 14:27:25 +0200 |
commit | 7376287554e30aa0b74136bf6c16566f6bda80cd (patch) | |
tree | 13b323d5a0b9eca9c5a3648aa099c48a80eb889c | |
parent | 70f7fd69b448263fc27b9dceba1663810f4885ab (diff) |
Fix race in phase lock contention counting
-rw-r--r-- | build2/b.cxx | 6 | ||||
-rw-r--r-- | libbuild2/context.cxx | 12 | ||||
-rw-r--r-- | libbuild2/context.hxx | 3 |
3 files changed, 12 insertions, 9 deletions
diff --git a/build2/b.cxx b/build2/b.cxx index e615ef5..b14da09 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -423,7 +423,8 @@ main (int argc, char* argv[]) { if (pctx != nullptr) { - phase_switch_contention += pctx->phase_mutex.contention; + phase_switch_contention += (pctx->phase_mutex.contention + + pctx->phase_mutex.contention_load); pctx = nullptr; // Free first to reuse memory. } @@ -1402,7 +1403,8 @@ main (int argc, char* argv[]) } #endif - phase_switch_contention += pctx->phase_mutex.contention; + phase_switch_contention += (pctx->phase_mutex.contention + + pctx->phase_mutex.contention_load); } catch (const failed&) { diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx index d460fa7..8052716 100644 --- a/libbuild2/context.cxx +++ b/libbuild2/context.cxx @@ -765,7 +765,7 @@ namespace build2 } else if (ctx_.phase != n) { - ++contention; + ++contention; // Protected by m_. ctx_.sched.deactivate (false /* external */); for (; ctx_.phase != n; v->wait (l)) ; @@ -783,11 +783,11 @@ namespace build2 { if (!lm_.try_lock ()) { - ++contention; - ctx_.sched.deactivate (false /* external */); lm_.lock (); ctx_.sched.activate (false /* external */); + + ++contention_load; // Protected by lm_. } r = !fail_; // Re-query. } @@ -905,7 +905,7 @@ namespace build2 } else // phase != n { - ++contention; + ++contention; // Protected by m_. ctx_.sched.deactivate (false /* external */); for (; ctx_.phase != n; v->wait (l)) ; @@ -919,11 +919,11 @@ namespace build2 { if (!lm_.try_lock ()) { - ++contention; - ctx_.sched.deactivate (false /* external */); lm_.lock (); ctx_.sched.activate (false /* external */); + + ++contention_load; // Protected by lm_. } r = !fail_; // Re-query. } diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx index 0595413..fbdf9b8 100644 --- a/libbuild2/context.hxx +++ b/libbuild2/context.hxx @@ -46,7 +46,8 @@ namespace build2 // Statistics. // public: - size_t contention = 0; // # of contentious phase (re)locks. + size_t contention = 0; // # of contentious phase (re)locks. + size_t contention_load = 0; // # of contentious load phase locks. private: friend class context; |