================
@@ -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; });
----------------
artemcm wrote:
`std::condition_variable` does not actually hold the lock while waiting, so I
think this is okay:
https://en.cppreference.com/cpp/thread/condition_variable/wait
> wait causes the current thread to block until the condition variable is
> notified or a spurious wakeup occurs. pred can be optionally provided to
> detect spurious wakeup.
> 1) Atomically calls lock.unlock() and blocks on *this.
The thread will be unblocked when notify_all() or notify_one() is executed. It
may also be unblocked spuriously.
When unblocked, calls lock.lock() (possibly blocking on the lock), then
returns.
https://github.com/llvm/llvm-project/pull/199680
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits