aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/cc
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-01-27 09:42:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-01-27 09:42:19 +0200
commit9e47b1fdea6fe589c531c5c649a9f1c22bc3a029 (patch)
treef62d9fc83b30b52b6dbd3fa42f146e7b72ed8005 /libbuild2/cc
parent2169f0e960c6e2b94518c03e6eb0406908b96e65 (diff)
Protect cc guess cache with mutex
Diffstat (limited to 'libbuild2/cc')
-rw-r--r--libbuild2/cc/guess.cxx13
1 files changed, 12 insertions, 1 deletions
diff --git a/libbuild2/cc/guess.cxx b/libbuild2/cc/guess.cxx
index d5fc884..182a997 100644
--- a/libbuild2/cc/guess.cxx
+++ b/libbuild2/cc/guess.cxx
@@ -2770,6 +2770,7 @@ namespace build2
// several times) so we cache the result.
//
static map<string, compiler_info> cache;
+ static mutex cache_mutex;
const compiler_info&
guess (const char* xm,
@@ -2800,6 +2801,8 @@ namespace build2
if (x_lo != nullptr) append_options (cs, *x_lo);
key = cs.string ();
+ mlock l (cache_mutex);
+
auto i (cache.find (key));
if (i != cache.end ())
return i->second;
@@ -2949,7 +2952,15 @@ namespace build2
r.bin_pattern = p.directory ().representation (); // Trailing slash.
}
- return (cache[key] = move (r));
+ // It's possible the cache entry already exists, in which case we
+ // ignore our value.
+ //
+ // But what if the compiler information it contains is different? Well,
+ // we don't generally deal with toolchain changes during the build so we
+ // ignore this special case as well.
+ //
+ mlock l (cache_mutex);
+ return cache.insert (make_pair (move (key), move (r))).first->second;
}
strings