From 912ac87012ffc2fd0c6fb21823a0244c787ce5ba Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Apr 2022 07:38:22 +0200 Subject: Avoid locking target set if in load phase --- libbuild2/algorithm.cxx | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'libbuild2/algorithm.cxx') 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 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 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. -- cgit v1.1