From 88f0780e34116c0441a8d8c58b8a8fd9fde4b1f5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 25 Jan 2017 15:41:44 +0200 Subject: Add model mutex, make var_pool const by default --- build2/dist/init.cxx | 32 ++++++++++++++++---------------- build2/dist/operation.cxx | 23 +++++++++++++++++------ build2/dist/rule | 4 ++-- build2/dist/rule.cxx | 8 ++++---- 4 files changed, 39 insertions(+), 28 deletions(-) (limited to 'build2/dist') diff --git a/build2/dist/init.cxx b/build2/dist/init.cxx index 901e9c2..9ee2d46 100644 --- a/build2/dist/init.cxx +++ b/build2/dist/init.cxx @@ -23,21 +23,21 @@ namespace build2 static const rule rule_; void - boot (scope& r, const location&, unique_ptr&) + boot (scope& rs, const location&, unique_ptr&) { tracer trace ("dist::boot"); - l5 ([&]{trace << "for " << r.out_path ();}); + l5 ([&]{trace << "for " << rs.out_path ();}); // Register meta-operation. // - r.meta_operations.insert (dist_id, dist); + rs.meta_operations.insert (dist_id, dist); // Enter module variables. Do it during boot in case they get assigned // in bootstrap.build (which is customary for, e.g., dist.package). // { - auto& v (var_pool); + auto& v (var_pool.rw (rs)); // Note: some overridable, some not. // @@ -63,7 +63,7 @@ namespace build2 } bool - init (scope& r, + init (scope& rs, scope&, const location& l, unique_ptr&, @@ -79,7 +79,7 @@ namespace build2 return true; } - const dir_path& out_root (r.out_path ()); + const dir_path& out_root (rs.out_path ()); l5 ([&]{trace << "for " << out_root;}); assert (config_hints.empty ()); // We don't known any hints. @@ -88,8 +88,8 @@ namespace build2 // to prevent something like insert(dist_id, test_id) // taking precedence. // - r.rules.insert (dist_id, 0, "dist", rule_); - r.rules.insert (dist_id, 0, "dist.alias", rule_); + rs.rules.insert (dist_id, 0, "dist", rule_); + rs.rules.insert (dist_id, 0, "dist.alias", rule_); // Configuration. // @@ -97,22 +97,22 @@ namespace build2 // must be explicitly specified or we will complain if and when // we try to dist. // - bool s (config::specified (r, "config.dist")); + bool s (config::specified (rs, "config.dist")); // Adjust module priority so that the config.dist.* values are saved at // the end of config.build. // if (s) - config::save_module (r, "dist", INT32_MAX); + config::save_module (rs, "dist", INT32_MAX); // dist.root // { - value& v (r.assign ("dist.root")); + value& v (rs.assign ("dist.root")); if (s) { - if (lookup l = config::optional (r, "config.dist.root")) + if (lookup l = config::optional (rs, "config.dist.root")) v = cast (l); // Strip abs_dir_path. } } @@ -120,11 +120,11 @@ namespace build2 // dist.cmd // { - value& v (r.assign ("dist.cmd")); + value& v (rs.assign ("dist.cmd")); if (s) { - if (lookup l = config::required (r, + if (lookup l = config::required (rs, "config.dist.cmd", path ("install")).first) v = run_search (cast (l), true); @@ -134,11 +134,11 @@ namespace build2 // dist.archives // { - value& v (r.assign ("dist.archives")); + value& v (rs.assign ("dist.archives")); if (s) { - if (lookup l = config::optional (r, "config.dist.archives")) + if (lookup l = config::optional (rs, "config.dist.archives")) v = *l; } } diff --git a/build2/dist/operation.cxx b/build2/dist/operation.cxx index 1b96282..83a5b01 100644 --- a/build2/dist/operation.cxx +++ b/build2/dist/operation.cxx @@ -30,7 +30,7 @@ namespace build2 } static void - dist_match (action, action_targets&) + dist_match (ulock&, action, action_targets&) { // Don't match anything -- see execute (). } @@ -54,7 +54,7 @@ namespace build2 const string& ext); static void - dist_execute (action, const action_targets& ts, bool) + dist_execute (ulock& ml, action, const action_targets& ts, bool) { tracer trace ("dist_execute"); @@ -97,6 +97,10 @@ namespace build2 const string& dist_package (cast (l)); const process_path& dist_cmd (cast (rs->vars["dist.cmd"])); + // Relock for shared access. @@ BOGUS + // + ml.unlock (); + // Get the list of operations supported by this project. Skip // default_id. // @@ -120,6 +124,9 @@ namespace build2 if (verb >= 6) dump (a); + slock sl (*ml.mutex ()); + model_lock = &sl; // @@ Guard? + for (void* v: ts) { target& t (*static_cast (v)); @@ -131,13 +138,17 @@ namespace build2 l5 ([&]{trace << diag_doing (a, t);}); - match (a, t); + match (sl, a, t); } + model_lock = nullptr; + if (verb >= 6) dump (a); } + ml.lock (); + // Add buildfiles that are not normally loaded as part of the // project, for example, the export stub. They will still be // ignored on the next step if the user explicitly marked them @@ -169,7 +180,7 @@ namespace build2 // The same for subprojects that have been loaded. // - if (auto l = rs->vars["subprojects"]) + if (auto l = rs->vars[var_subprojects]) { for (auto p: cast (l)) { @@ -247,8 +258,8 @@ namespace build2 action a (perform_id, update_id); - perform.match (a, files); - perform.execute (a, files, true); // Run quiet. + perform.match (ml, a, files); + perform.execute (ml, a, files, true); // Run quiet. if (perform.operation_post != nullptr) perform.operation_post (update_id); diff --git a/build2/dist/rule b/build2/dist/rule index db8e731..61be24f 100644 --- a/build2/dist/rule +++ b/build2/dist/rule @@ -22,10 +22,10 @@ namespace build2 rule () {} virtual match_result - match (action, target&, const string&) const override; + match (slock&, action, target&, const string&) const override; virtual recipe - apply (action, target&) const override; + apply (slock&, action, target&) const override; }; } } diff --git a/build2/dist/rule.cxx b/build2/dist/rule.cxx index 6cbd7df..f5c4018 100644 --- a/build2/dist/rule.cxx +++ b/build2/dist/rule.cxx @@ -16,17 +16,17 @@ namespace build2 namespace dist { match_result rule:: - match (action, target&, const string&) const + match (slock&, action, target&, const string&) const { return true; // We always match. } recipe rule:: - apply (action a, target& t) const + apply (slock& ml, action a, target& t) const { const dir_path& out_root (t.root_scope ().out_path ()); - auto r (group_prerequisite_members (a, t, false)); + auto r (group_prerequisite_members (ml, a, t, false)); for (auto i (r.begin ()); i != r.end (); ++i) { prerequisite_member p (*i); @@ -48,7 +48,7 @@ namespace build2 // Don't match targets that are outside of our project. // if (pt.dir.sub (out_root)) - build2::match (a, pt); + build2::match (ml, a, pt); } return noop_recipe; // We will never be executed. -- cgit v1.1