From 4a2a3bd5033744c31377d31ca54be00622280a1b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 26 Feb 2024 09:14:37 +0200 Subject: Add ability to request serialization from scheduler In particular, this can be used to make sure no other recipe is being executed in parallel with the caller. --- libbuild2/context.cxx | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'libbuild2/context.cxx') diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx index c0442f0..6e4fd6f 100644 --- a/libbuild2/context.cxx +++ b/libbuild2/context.cxx @@ -1124,35 +1124,35 @@ namespace build2 // phase_unlock // phase_unlock:: - phase_unlock (context& c, bool u, bool d) - : ctx (u ? &c : nullptr), lock (nullptr) + phase_unlock (context* c, bool d) + : ctx (c), lock_ (nullptr) { - if (u && !d) + if (ctx != nullptr && !d) unlock (); } void phase_unlock:: unlock () { - if (ctx != nullptr && lock == nullptr) + if (ctx != nullptr && lock_ == nullptr) { - lock = phase_lock_instance; - assert (&lock->ctx == ctx); + lock_ = phase_lock_instance; + assert (&lock_->ctx == ctx); phase_lock_instance = nullptr; // Note: not lock->prev. - ctx->phase_mutex.unlock (lock->phase); + ctx->phase_mutex.unlock (lock_->phase); - //text << this_thread::get_id () << " phase unlock " << lock->phase; + //text << this_thread::get_id () << " phase unlock " << lock_->phase; } } - phase_unlock:: - ~phase_unlock () noexcept (false) + void phase_unlock:: + lock () { - if (lock != nullptr) + if (lock_ != nullptr) { - bool r (ctx->phase_mutex.lock (lock->phase)); - phase_lock_instance = lock; + bool r (ctx->phase_mutex.lock (lock_->phase)); + phase_lock_instance = lock_; // Fail unless we are already failing. Note that we keep the phase // locked since there will be phase_lock down the stack to unlock it. @@ -1160,10 +1160,16 @@ namespace build2 if (!r && !uncaught_exception ()) throw failed (); - //text << this_thread::get_id () << " phase lock " << lock->phase; + //text << this_thread::get_id () << " phase lock " << lock_->phase; } } + phase_unlock:: + ~phase_unlock () noexcept (false) + { + lock (); + } + // phase_switch // phase_switch:: -- cgit v1.1