Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from the std::shared_mutex to an LLVM RWMutex #74383

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

kevinfrei
Copy link
Contributor

@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

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 4, 2023

@llvm/pr-subscribers-debuginfo

Author: Kevin Frei (kevinfrei)

Changes

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

Copy link
Contributor

@nico nico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, thanks!

@nico nico merged commit 89e775a into llvm:main Dec 5, 2023
4 checks passed
@kevinfrei kevinfrei deleted the macos10-12-mutex-issue branch December 19, 2023 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants