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/scope | 59 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 26 deletions(-) (limited to 'build2/scope') diff --git a/build2/scope b/build2/scope index eff60b0..16ddfbb 100644 --- a/build2/scope +++ b/build2/scope @@ -94,9 +94,17 @@ namespace build2 } lookup + operator[] (const variable* var) const // For cached variables. + { + assert (var != nullptr); + return operator[] (*var); + } + + lookup operator[] (const string& name) const { - return operator[] (var_pool[name]); + const variable* var (var_pool.find (name)); + return var != nullptr ? operator[] (*var) : lookup (); } // As above, but include target type/pattern-specific variables. @@ -108,23 +116,11 @@ namespace build2 } lookup - find (const string& var, const target_key& tk) const - { - return find (var_pool[var], tk); - } - - lookup find (const variable& var, const target_type& tt, const string& tn) const { return find (var, &tt, &tn).first; } - lookup - find (const string& var, const target_type& tt, const string& tn) const - { - return find (var_pool[var], tt, tn); - } - pair find (const variable& var, const target_type* tt = nullptr, @@ -149,24 +145,35 @@ namespace build2 pair original, bool target = false) const; - // Return a value suitable for assignment (or append if you only - // want to append to the value from this scope). If the variable - // does not exist in this scope's map, then a new one with the - // NULL value is added and returned. Otherwise the existing value - // is returned. + // Return a value suitable for assignment (or append if you only want to + // append to the value from this scope). If the value does not exist in + // this scope's map, then a new one with the NULL value is added and + // returned. Otherwise the existing value is returned. // value& assign (const variable& var) {return vars.assign (var);} value& - assign (const string& name) {return vars.assign (name);} + assign (const variable* var) // For cached variables. + { + assert (var != nullptr); + return vars.assign (*var); + } + + value& + assign (string name) + { + return assign (variable_pool::instance.insert (move (name))); + } - // Unlike the two above, assign a typed non-overridable variable with - // normal visibility. + // Assign a typed non-overridable variable with normal visibility. // template value& - assign (string name) {return vars.assign (move (name));} + assign (string name) + { + return vars.assign (variable_pool::instance.insert (move (name))); + } // Return a value suitable for appending. If the variable does not // exist in this scope's map, then outer scopes are searched for @@ -177,9 +184,6 @@ namespace build2 value& append (const variable&); - value& - append (const string& name) {return append (var_pool[name]);} - // Target type/pattern-specific variables. // variable_type_map target_vars; @@ -278,7 +282,10 @@ namespace build2 } }; - // Note that the scope map is only for paths from the out tree. + // Scope map. + // + // Protected by the model mutex. Note that the scope map is only for paths + // from the out tree. // using scope_map_base = butl::dir_path_map; -- cgit v1.1