[llvm] Switch from the std::shared_mutex to an LLVM RWMutex (PR #74383)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 4 15:29:44 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Kevin Frei (kevinfrei)

<details>
<summary>Changes</summary>

@<!-- -->nico pointed out that my usage of `std::shared_mutex` broke builds on older macOS devices. Switching to `llvm::sys::RWMutex` is the solution that they provided.

Tracked in issue #<!-- -->74382 

---
Full diff: https://github.com/llvm/llvm-project/pull/74383.diff


1 Files Affected:

- (modified) llvm/lib/Debuginfod/Debuginfod.cpp (+4-4) 


``````````diff
diff --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index c1cab8d79cabd..9df30ab55cbad 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -51,7 +51,7 @@ using llvm::object::BuildIDRef;
 namespace {
 std::optional<SmallVector<StringRef>> DebuginfodUrls;
 // Many Readers/Single Writer lock protecting the global debuginfod URL list.
-std::shared_mutex UrlsMutex;
+llvm::sys::RWMutex UrlsMutex;
 } // namespace
 
 static std::string uniqueKey(llvm::StringRef S) {
@@ -69,12 +69,12 @@ bool canUseDebuginfod() {
 }
 
 SmallVector<StringRef> getDefaultDebuginfodUrls() {
-  std::shared_lock<std::shared_mutex> ReadGuard(UrlsMutex);
+  std::shared_lock<llvm::sys::RWMutex> ReadGuard(UrlsMutex);
   if (!DebuginfodUrls) {
     // Only read from the environment variable if the user hasn't already
     // set the value
     ReadGuard.unlock();
-    std::unique_lock<std::shared_mutex> WriteGuard(UrlsMutex);
+    std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
     DebuginfodUrls = SmallVector<StringRef>();
     if (const char *DebuginfodUrlsEnv = std::getenv("DEBUGINFOD_URLS")) {
       StringRef(DebuginfodUrlsEnv)
@@ -88,7 +88,7 @@ SmallVector<StringRef> getDefaultDebuginfodUrls() {
 
 // Set the default debuginfod URL list, override the environment variable
 void setDefaultDebuginfodUrls(const SmallVector<StringRef> &URLs) {
-  std::unique_lock<std::shared_mutex> WriteGuard(UrlsMutex);
+  std::unique_lock<llvm::sys::RWMutex> WriteGuard(UrlsMutex);
   DebuginfodUrls = URLs;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/74383


More information about the llvm-commits mailing list