aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/cc/guess.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-12-15 09:25:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-12-15 09:31:59 +0200
commitf7a245b2b6091ef3a5e1193423c7fbbd6fe6a538 (patch)
tree28b3006840b718084f229820e0408b0712674232 /libbuild2/cc/guess.cxx
parent8c9b0fb944a60d8193d8ac3dbac4e8e15f81bf57 (diff)
Cache more results of executing programs (compilers, etc)
Diffstat (limited to 'libbuild2/cc/guess.cxx')
-rw-r--r--libbuild2/cc/guess.cxx20
1 files changed, 4 insertions, 16 deletions
diff --git a/libbuild2/cc/guess.cxx b/libbuild2/cc/guess.cxx
index 5a2e3b3..daa9d9b 100644
--- a/libbuild2/cc/guess.cxx
+++ b/libbuild2/cc/guess.cxx
@@ -2956,8 +2956,7 @@ namespace build2
// Compiler checks can be expensive (we often need to run the compiler
// several times) so we cache the result.
//
- static map<string, compiler_info> cache;
- static mutex cache_mutex;
+ static global_cache<compiler_info> cache;
const compiler_info&
guess (const char* xm,
@@ -2988,11 +2987,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;
+ if (const compiler_info* r = cache.find (key))
+ return *r;
}
// Parse the user-specified compiler id (config.x.id).
@@ -3144,15 +3140,7 @@ namespace build2
r.bin_pattern = p.directory ().representation (); // Trailing slash.
}
- // 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;
+ return cache.insert (move (key), move (r));
}
strings