aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/algorithm.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-04-18 07:38:22 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-04-18 07:38:22 +0200
commit912ac87012ffc2fd0c6fb21823a0244c787ce5ba (patch)
tree4861fd4b2bcdcfb61b97f215e3a24efaca25af57 /libbuild2/algorithm.cxx
parent56e38cffbd730e66261d9da29c8da91d39ebb167 (diff)
Avoid locking target set if in load phase
Diffstat (limited to 'libbuild2/algorithm.cxx')
-rw-r--r--libbuild2/algorithm.cxx38
1 files changed, 22 insertions, 16 deletions
diff --git a/libbuild2/algorithm.cxx b/libbuild2/algorithm.cxx
index 5011b26..8ef88e4 100644
--- a/libbuild2/algorithm.cxx
+++ b/libbuild2/algorithm.cxx
@@ -332,22 +332,28 @@ namespace build2
if (*mp != nullptr) // Might already be there.
return **mp;
- pair<target&, ulock> r (
- t.ctx.targets.insert_locked (tt,
- move (dir),
- move (out),
- move (n),
- nullopt /* ext */,
- target_decl::implied,
- trace));
-
- assert (r.second);
-
- target& m (r.first);
- *mp = &m;
- m.group = &t;
-
- return m;
+ target* m (nullptr);
+ {
+ pair<target&, ulock> r (
+ t.ctx.targets.insert_locked (tt,
+ move (dir),
+ move (out),
+ move (n),
+ nullopt /* ext */,
+ target_decl::implied,
+ trace));
+
+ if (r.second) // Inserted.
+ {
+ m = &r.first;
+ m->group = &t;
+ }
+ }
+
+ assert (m != nullptr);
+ *mp = m;
+
+ return *m;
};
// Return the matching rule or NULL if no match and try_match is true.