================
@@ -184,6 +184,101 @@ DependencyScanningFilesystemSharedCache::CacheShard::
return *CachedEntry;
}
+DependencyScanningFilesystemSharedCache::SlotAcquisitionResult
+DependencyScanningFilesystemSharedCache::CacheShard::acquireFilenameSlot(
+ StringRef Filename) {
+ assert(llvm::sys::path::is_absolute_gnu(Filename));
+ std::unique_lock<std::mutex> LockGuard(CacheLock);
+ // Cache hit.
+ if (auto It = CacheByFilename.find(Filename); It != CacheByFilename.end()) {
+ if (const auto *Entry = It->getValue().first)
+ return SlotAcquisitionResult{Entry, nullptr};
+ }
+
+ // Another worker is producing for this filename, wait for it.
+ if (auto It = InProgressByFilename.find(Filename);
+ It != InProgressByFilename.end()) {
+ std::shared_ptr<InProgressEntry> Pending = It->second;
+ Pending->CondVar.wait(LockGuard, [&] { return Pending->Done; });
+ assert(Pending->Result &&
+ "in-progress filename slot fulfilled without an entry");
+ return SlotAcquisitionResult{Pending->Result, nullptr};
+ }
+
+ // Install an in-progress entry and return it.
+ auto Pending = std::make_shared<InProgressEntry>();
+ InProgressByFilename.try_emplace(Filename, Pending);
+ return SlotAcquisitionResult{nullptr, std::move(Pending)};
+}
+
+DependencyScanningFilesystemSharedCache::SlotAcquisitionResult
+DependencyScanningFilesystemSharedCache::CacheShard::acquireUIDSlot(
+ llvm::sys::fs::UniqueID UID) {
+ std::unique_lock<std::mutex> LockGuard(CacheLock);
+ // Cache hit.
+ if (auto It = EntriesByUID.find(UID); It != EntriesByUID.end())
+ return SlotAcquisitionResult{It->getSecond(), nullptr};
+
+ // Another worker is producing for this UID, wait for it.
+ if (auto It = InProgressByUID.find(UID); It != InProgressByUID.end()) {
+ std::shared_ptr<InProgressEntry> Pending = It->second;
+ Pending->CondVar.wait(LockGuard, [&] { return Pending->Done; });
----------------
jansvoboda11 wrote:
Same thing as above.
https://github.com/llvm/llvm-project/pull/199680
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits