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

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


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

@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 

>From f5a1aeedd03e8e9369756d48abfdbd36e38b7ed8 Mon Sep 17 00:00:00 2001
From: Kevin Frei <freik at meta.com>
Date: Mon, 4 Dec 2023 15:24:27 -0800
Subject: [PATCH] Switch from the std::shared_mutex to an LLVM RWMutex

---
 llvm/lib/Debuginfod/Debuginfod.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

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;
 }
 



More information about the llvm-commits mailing list