20 template <
typename CompilationContext>
23 std::lock_guard<std::mutex> lock(code_cache_mutex_);
25 auto it = code_cache_.find(key);
26 if (it != code_cache_.cend()) {
33 template <
typename CompilationContext>
38 std::lock_guard<std::mutex> lock(code_cache_mutex_);
40 auto it = code_cache_.find(key);
42 if (it == code_cache_.cend()) {
43 code_cache_.put(key, value);
50 LOG(
WARNING) << *
this <<
": code already in cache, ignoring.\n";
54 template <
typename CompilationContext>
58 std::unique_lock<std::mutex> lk(code_cache_mutex_);
60 cached_code = code_cache_.get(key);
62 if (cached_code->get()) {
73 compilation_cv_.wait(lk, [&] {
return !!(code_cache_.get(key)->get()); });
74 cached_code = code_cache_.get(key);
75 CHECK(cached_code->get());
85 code_cache_.put(key, std::move(not_a_code));
89 template <
typename CompilationContext>
93 std::lock_guard<std::mutex> lock(code_cache_mutex_);
94 auto result = code_cache_.get(key);
98 compilation_cv_.notify_all();
101 template <
typename CompilationContext>
103 std::lock_guard<std::mutex> lock(code_cache_mutex_);
std::shared_ptr< CC > CodeCacheVal
CodeCacheVal< CompilationContext > get_value(const CodeCacheKey &key)
std::vector< std::string > CodeCacheKey
void swap(const CodeCacheKey &key, CodeCacheVal< CompilationContext > &&value)
CodeCacheVal< CompilationContext > * get_or_wait(const CodeCacheKey &key)
void put(const CodeCacheKey &key, CodeCacheVal< CompilationContext > &value)