diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2024-12-12 11:30:27 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2024-12-12 11:30:27 +0200 |
commit | d27390e9935c94938af9e7068557d6f6ef9b07a9 (patch) | |
tree | 2c27fc4e49e51d90ea246607160d8b2790973693 /libbuild2 | |
parent | 270041729e2d2f67d15e419e314cda4eba9821f6 (diff) |
Increment load_generation between operations in batch
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/cc/init.cxx | 2 | ||||
-rw-r--r-- | libbuild2/context.cxx | 7 | ||||
-rw-r--r-- | libbuild2/context.hxx | 19 | ||||
-rw-r--r-- | libbuild2/module.cxx | 2 |
4 files changed, 26 insertions, 4 deletions
diff --git a/libbuild2/cc/init.cxx b/libbuild2/cc/init.cxx index d691bc5..64c70f8 100644 --- a/libbuild2/cc/init.cxx +++ b/libbuild2/cc/init.cxx @@ -764,7 +764,7 @@ namespace build2 perform_update_id, context::operation_callback {&compiledb_pre, &compiledb_post}); - if (ctx.load_generation > 1) + if (!ctx.phase_mutex.unlocked ()) // Interrupting load. { action a (ctx.current_action ()); diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx index 6e4fd6f..31d218b 100644 --- a/libbuild2/context.cxx +++ b/libbuild2/context.cxx @@ -1061,6 +1061,13 @@ namespace build2 return r ? optional<bool> (s) : nullopt; } + bool run_phase_mutex:: + unlocked () const + { + mlock l (m_); + return lc_ == 0 && mc_ == 0 && ec_ == 0; + } + // C++17 deprecated uncaught_exception() so use uncaught_exceptions() if // available. // diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx index 46dbfaa..12b11d5 100644 --- a/libbuild2/context.hxx +++ b/libbuild2/context.hxx @@ -49,6 +49,12 @@ namespace build2 optional<bool> relock (run_phase unlock, run_phase lock); + // Return true if the mutex is unlocked, meaning we are in the initial + // load phase. + // + bool + unlocked () const; + // Statistics. // public: @@ -78,7 +84,7 @@ namespace build2 // context& ctx_; - mutex m_; + mutable mutex m_; bool fail_; @@ -209,8 +215,12 @@ namespace build2 // hierarchy would "see" a new value from the newly inserted scope. // // The special load_generation value 0 indicates initialization before - // anything has been loaded. Currently, it is changed to 1 at the end - // of the context constructor. + // anything has been loaded. Currently, it is changed to 1 at the end of + // the context constructor. Note also that subsequent operations in a + // batch may trigger loading of additional buildfiles, in fact, entire new + // projects. As a result, load_generation is also incremented after each + // operation in a batch. If you need to detect the initial load in each + // operation, check that phase_mutex is unlocked. // // Note must come (and thus initialized) before the data_ member. // @@ -817,6 +827,9 @@ namespace build2 // Set current meta-operation and operation. // + // Remember to also increment load_generation for subsequent operations in + // a batch if additional buildfiles are loaded between them. + // // Note that the context instance is not to be re-used between different // meta-operations. // diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx index df0da48..9a12d01 100644 --- a/libbuild2/module.cxx +++ b/libbuild2/module.cxx @@ -204,6 +204,8 @@ namespace build2 0, /* diag (none) */ false /* progress */); + ctx.module_context->load_generation++; + assert (tgs.size () == 1); return tgs[0].as<target> (); } |