Skip to content

[clang-doc] Use SmartMutex when visiting the AST #135514

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

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

ilovepi
Copy link
Contributor

@ilovepi ilovepi commented Apr 13, 2025

The SmartMutex will allow us to have a cheap mutex implementation when
using the Standalone executor, since it's single threaded. Performance
should be about the same for AllTUs executor.

The SmartMutex will allow us to have a cheap mutex implementation when
using the Standalone executor, since it's single threaded. Performance
should be about the same for AllTUs executor.
Copy link
Contributor Author

ilovepi commented Apr 13, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ilovepi ilovepi marked this pull request as ready for review April 13, 2025 02:40
@llvmbot
Copy link
Member

llvmbot commented Apr 13, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Paul Kirth (ilovepi)

Changes

The SmartMutex will allow us to have a cheap mutex implementation when
using the Standalone executor, since it's single threaded. Performance
should be about the same for AllTUs executor.


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

1 Files Affected:

  • (modified) clang-tools-extra/clang-doc/Mapper.cpp (+2-2)
diff --git a/clang-tools-extra/clang-doc/Mapper.cpp b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..022e3b12d82bc 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -19,7 +19,7 @@ namespace clang {
 namespace doc {
 
 static llvm::StringSet<> USRVisited;
-static llvm::sys::Mutex USRVisitedGuard;
+static llvm::sys::SmartMutex<true> USRVisitedGuard;
 
 template <typename T> bool isTypedefAnonRecord(const T *D) {
   if (const auto *C = dyn_cast<CXXRecordDecl>(D)) {
@@ -48,7 +48,7 @@ bool MapASTVisitor::mapDecl(const T *D, bool IsDefinition) {
     return true;
   // Prevent Visiting USR twice
   {
-    std::lock_guard<llvm::sys::Mutex> Guard(USRVisitedGuard);
+    llvm::sys::SmartScopedLock<true> Guard(USRVisitedGuard);
     StringRef Visited = USR.str();
     if (USRVisited.count(Visited) && !isTypedefAnonRecord<T>(D))
       return true;

Copy link
Contributor Author

ilovepi commented Apr 15, 2025

Merge activity

  • Apr 14, 8:26 PM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Apr 14, 8:27 PM EDT: A user merged this pull request with Graphite.

@ilovepi ilovepi merged commit 9cdc3aa into main Apr 15, 2025
15 checks passed
@ilovepi ilovepi deleted the users/ilovepi/clang-doc-lock branch April 15, 2025 00:27
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.

3 participants