aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/target.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-04-12 11:39:55 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-04-13 10:55:55 +0200
commitdc8f0267c332e405a698545c98478756165c908e (patch)
treee012a02a183bb25ea116e693dbdb51983ca0a85f /libbuild2/target.cxx
parent7376287554e30aa0b74136bf6c16566f6bda80cd (diff)
Cache target base scope lookups
Diffstat (limited to 'libbuild2/target.cxx')
-rw-r--r--libbuild2/target.cxx25
1 files changed, 15 insertions, 10 deletions
diff --git a/libbuild2/target.cxx b/libbuild2/target.cxx
index 92db7e9..1806e61 100644
--- a/libbuild2/target.cxx
+++ b/libbuild2/target.cxx
@@ -115,22 +115,27 @@ namespace build2
}
const scope& target::
- base_scope () const
+ base_scope_impl () const
{
// If this target is from the src tree, use its out directory to find
// the scope.
//
- return ctx.scopes.find_out (out_dir ());
- }
+ const scope& s (ctx.scopes.find_out (out_dir ()));
- const scope& target::
- root_scope () const
- {
- // This is tricky to cache so we do the lookup for now.
+ // Cache unless we are in the load phase.
//
- const scope* r (base_scope ().root_scope ());
- assert (r != nullptr);
- return *r;
+ if (ctx.phase != run_phase::load)
+ {
+ const scope* e (nullptr);
+ if (!base_scope_.compare_exchange_strong (
+ e,
+ &s,
+ memory_order_release,
+ memory_order_consume))
+ assert (e == &s);
+ }
+
+ return s;
}
pair<lookup, size_t> target::