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/context.cxx | 60 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 19 deletions(-) (limited to 'build2/context.cxx') diff --git a/build2/context.cxx b/build2/context.cxx index ba6629c..1cf3dd9 100644 --- a/build2/context.cxx +++ b/build2/context.cxx @@ -23,6 +23,26 @@ using namespace butl; namespace build2 { + shared_mutex model; + +#ifdef __cpp_thread_local + thread_local +#else + __thread +#endif + slock* model_lock; + + const variable* var_src_root; + const variable* var_out_root; + const variable* var_src_base; + const variable* var_out_base; + + const variable* var_project; + const variable* var_amalgamation; + const variable* var_subprojects; + + const variable* var_import_target; + const string* current_mname; const string* current_oname; @@ -37,7 +57,7 @@ namespace build2 variable_override_cache var_override_cache; variable_overrides - reset (const strings& cmd_vars) + reset (const ulock& ml, const strings& cmd_vars) { tracer trace ("reset"); @@ -46,13 +66,15 @@ namespace build2 l6 ([&]{trace << "resetting build state";}); + auto& vp (var_pool.rw (ml)); + variable_overrides vos; var_override_cache.clear (); targets.clear (); scopes.clear (); - var_pool.clear (); + vp.clear (); // Reset meta/operation tables. Note that the order should match the id // constants in . @@ -147,7 +169,7 @@ namespace build2 c == '%' ? variable_visibility::project : variable_visibility::normal); - const variable& var (var_pool[n]); + const variable& var (vp.insert (n)); const char* k (tt == token_type::assign ? ".__override" : tt == token_type::append ? ".__suffix" : ".__prefix"); @@ -209,23 +231,23 @@ namespace build2 // Enter builtin variables. // - { - auto& v (var_pool); - - v.insert ("src_root"); - v.insert ("out_root"); - v.insert ("src_base"); - v.insert ("out_base"); + var_src_root = &vp.insert ("src_root"); + var_out_root = &vp.insert ("out_root"); + var_src_base = &vp.insert ("src_base"); + var_out_base = &vp.insert ("out_base"); - v.insert ("project"); - v.insert ("amalgamation"); + // Note that subprojects is not typed since the value requires + // pre-processing (see file.cxx). + // + var_project = &vp.insert ("project"); + var_amalgamation = &vp.insert ("amalgamation"); + var_subprojects = &vp.insert ("subprojects"); - // Not typed since the value requires pre-processing (see file.cxx). - // - v.insert ("subprojects"); + var_import_target = &vp.insert ("import.target"); - v.insert ("extension", variable_visibility::target); - } + // Target extension. + // + vp.insert ("extension", variable_visibility::target); gs.assign ("build.work") = work; gs.assign ("build.home") = home; @@ -240,8 +262,8 @@ namespace build2 // Build system version. // { - gs.assign ("build.version") = uint64_t (BUILD2_VERSION); - gs.assign ("build.version.string") = BUILD2_VERSION_STR; + gs.assign ("build.version") = uint64_t (BUILD2_VERSION); + gs.assign ("build.version.string") = BUILD2_VERSION_STR; // AABBCCDD // -- cgit v1.1