From febfafcf7f0e4d1cbe878e7dfffd9c9b78036aed Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 5 Dec 2017 17:34:00 +0200 Subject: Add support for first-access value typification during non-load phases --- build2/variable.ixx | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'build2/variable.ixx') diff --git a/build2/variable.ixx b/build2/variable.ixx index d7c4326..0a235e5 100644 --- a/build2/variable.ixx +++ b/build2/variable.ixx @@ -232,7 +232,7 @@ namespace build2 inline void typify (value& v, const variable* var) { - value_type& t (value_traits::value_type); + const value_type& t (value_traits::value_type); if (v.type != &t) typify (v, t, var); @@ -689,6 +689,25 @@ namespace build2 return i != map_.end () ? &i->second : nullptr; } + // variable_map + // + inline void variable_map:: + typify (const value_data& v, const variable& var) const + { + // We assume typification is not modification so no version increment. + // + if (phase == run_phase::load) + { + if (v.type != var.type) + build2::typify (const_cast (v), *var.type, &var); + } + else + { + if (v.type.load (memory_order_acquire) != var.type) + build2::typify_atomic (const_cast (v), *var.type, &var); + } + } + // variable_map::iterator_adapter // template @@ -699,15 +718,10 @@ namespace build2 const variable& var (r.first); const value_data& val (r.second); - // First access after being assigned a type? + // Check if this is the first access after being assigned a type. // - if (var.type != nullptr && val.type != var.type) - { - // All values shall be typed during load. - // - assert (!m_->global_ || phase == run_phase::load); - m_->typify (const_cast (val), var); - } + if (var.type != nullptr) + m_->typify (val, var); return r; } @@ -720,15 +734,10 @@ namespace build2 const variable& var (p->first); const value_data& val (p->second); - // First access after being assigned a type? + // Check if this is the first access after being assigned a type. // - if (var.type != nullptr && val.type != var.type) - { - // All values shall be typed during load. - // - assert (!m_->global_ || phase == run_phase::load); - m_->typify (const_cast (val), var); - } + if (var.type != nullptr) + m_->typify (val, var); return p; } -- cgit v1.1