aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/context.cxx8
-rw-r--r--libbuild2/context.hxx7
2 files changed, 14 insertions, 1 deletions
diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx
index 80343bd..d460fa7 100644
--- a/libbuild2/context.cxx
+++ b/libbuild2/context.cxx
@@ -765,6 +765,8 @@ namespace build2
}
else if (ctx_.phase != n)
{
+ ++contention;
+
ctx_.sched.deactivate (false /* external */);
for (; ctx_.phase != n; v->wait (l)) ;
r = !fail_;
@@ -781,6 +783,8 @@ namespace build2
{
if (!lm_.try_lock ())
{
+ ++contention;
+
ctx_.sched.deactivate (false /* external */);
lm_.lock ();
ctx_.sched.activate (false /* external */);
@@ -901,6 +905,8 @@ namespace build2
}
else // phase != n
{
+ ++contention;
+
ctx_.sched.deactivate (false /* external */);
for (; ctx_.phase != n; v->wait (l)) ;
r = !fail_;
@@ -913,6 +919,8 @@ namespace build2
{
if (!lm_.try_lock ())
{
+ ++contention;
+
ctx_.sched.deactivate (false /* external */);
lm_.lock ();
ctx_.sched.activate (false /* external */);
diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx
index ef628c9..0595413 100644
--- a/libbuild2/context.hxx
+++ b/libbuild2/context.hxx
@@ -43,6 +43,11 @@ namespace build2
bool
relock (run_phase unlock, run_phase lock);
+ // Statistics.
+ //
+ public:
+ size_t contention = 0; // # of contentious phase (re)locks.
+
private:
friend class context;
@@ -61,7 +66,7 @@ namespace build2
// is exclusive so we have a separate mutex to serialize it (think of it
// as a second level locking).
//
- // When the mutex is unlocked (all three counters become zero, the phase
+ // When the mutex is unlocked (all three counters become zero), the phase
// is always changed to load (this is also the initial state).
//
context& ctx_;