12#include "llvm/Support/AdvisoryLock.h"
13#include "llvm/Support/Chrono.h"
18using namespace tooling;
19using namespace dependencies;
22class ReaderWriterLock :
public llvm::AdvisoryLock {
24 std::unique_lock<std::shared_mutex> OwningLock;
27 ReaderWriterLock(std::shared_mutex &Mutex)
28 : OwningLock(Mutex,
std::defer_lock) {}
30 Expected<bool> tryLock()
override {
return OwningLock.try_lock(); }
32 llvm::WaitForUnlockResult
33 waitForUnlockFor(std::chrono::seconds MaxSeconds)
override {
39 std::shared_lock<std::shared_mutex> Lock(*OwningLock.mutex());
40 return llvm::WaitForUnlockResult::Success;
43 std::error_code unsafeMaybeUnlock()
override {
50 ~ReaderWriterLock()
override =
default;
67 std::unique_ptr<llvm::AdvisoryLock>
getLock(StringRef
Filename)
override {
68 auto &CompilationMutex = [&]() -> std::shared_mutex & {
69 std::lock_guard<std::mutex> Lock(Entries.
Mutex);
72 Entry = std::make_unique<ModuleCacheEntry>();
73 return Entry->CompilationMutex;
75 return std::make_unique<ReaderWriterLock>(CompilationMutex);
79 auto &Timestamp = [&]() -> std::atomic<std::time_t> & {
80 std::lock_guard<std::mutex> Lock(Entries.
Mutex);
83 Entry = std::make_unique<ModuleCacheEntry>();
84 return Entry->Timestamp;
87 return Timestamp.load();
92 auto &Timestamp = [&]() -> std::atomic<std::time_t> & {
93 std::lock_guard<std::mutex> Lock(Entries.
Mutex);
96 Entry = std::make_unique<ModuleCacheEntry>();
97 return Entry->Timestamp;
100 Timestamp.store(llvm::sys::toTimeT(std::chrono::system_clock::now()));
112 return llvm::makeIntrusiveRefCnt<InProcessModuleCache>(Entries);
In-memory cache for modules.
The module cache used for compiling modules implicitly.
virtual void prepareForGetLock(StringRef ModuleFilename)=0
May perform any work that only needs to be performed once for multiple calls getLock() with the same ...
virtual std::time_t getModuleTimestamp(StringRef ModuleFilename)=0
Returns the timestamp denoting the last time inputs of the module file were validated.
virtual InMemoryModuleCache & getInMemoryModuleCache()=0
Returns this process's view of the module cache.
virtual void updateModuleTimestamp(StringRef ModuleFilename)=0
Updates the timestamp denoting the last time inputs of the module file were validated.
virtual std::unique_ptr< llvm::AdvisoryLock > getLock(StringRef ModuleFilename)=0
Returns lock for the given module file. The lock is initially unlocked.
The JSON file list parser is used to communicate input to InstallAPI.