[clang] [clang][modules][deps] Add mutex as an alternative to file lock (PR #129751)
Michael Spencer via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 6 11:33:09 PST 2025
================
@@ -0,0 +1,31 @@
+#ifndef LLVM_CLANG_SERIALIZATION_MODULECACHELOCK_H
+#define LLVM_CLANG_SERIALIZATION_MODULECACHELOCK_H
+
+#include "clang/Basic/LLVM.h"
+#include "llvm/Support/LockFileManager.h"
+
+namespace clang {
+enum class LockResult { Owned, Shared, Error };
+enum class WaitForUnlockResult { Success, OwnerDied, Timeout };
+
+class ModuleCacheLockManager {
+public:
+ virtual operator LockResult() const = 0;
+ virtual WaitForUnlockResult waitForUnlock() = 0;
+ virtual void unsafeRemoveLock() = 0;
+ virtual std::string getErrorMessage() const = 0;
+ virtual ~ModuleCacheLockManager() = default;
+};
+
+class ModuleCacheLock {
+public:
+ virtual void prepareLock(StringRef ModuleFilename) = 0;
+ virtual std::unique_ptr<ModuleCacheLockManager>
+ tryLock(StringRef ModuleFilename) = 0;
+ virtual ~ModuleCacheLock() = default;
+};
----------------
Bigcheese wrote:
Hmm, `ModuleCacheLockManager` is basically the same interface, and the enums are the same. I do think it makes sense to have that part in llvm/Support. I think the `ModuleCacheLock` should stay in Clang though.
It would also be nice to modernize the interface (particularly `std::string getErrorMessage()`), but I think that can happen separately.
https://github.com/llvm/llvm-project/pull/129751
More information about the cfe-commits
mailing list