diff options
-rw-r--r-- | build2/b.cxx | 6 | ||||
-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 |
5 files changed, 32 insertions, 4 deletions
diff --git a/build2/b.cxx b/build2/b.cxx index 0b4ec3a..f357722 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -831,6 +831,12 @@ main (int argc, char* argv[]) if (!oname.empty () && lift ()) break; + // Increment load generation for subsequent operations in a batch + // since they may load additional buildfiles. + // + if (mid != 0) + ctx.load_generation++; + // Next bootstrap projects for all the target so that all the variable // overrides are set (if we also load/search/match in the same loop // then we may end up loading a project (via import) before this 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> (); } |