From: Benjamin Kramer Date: Wed, 7 Aug 2019 11:59:44 +0000 (+0000) Subject: Replace non-recursive sys::Mutex users with std::mutex X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=838c29d0589c827bb857e38ca52616d18e17f86d;p=clang Replace non-recursive sys::Mutex users with std::mutex Also remove a use of sys::MutexImpl, that's just evil. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368157 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 7fb1d2d933..4491bf298c 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -390,7 +390,7 @@ private: /// just about any usage. /// Becomes a noop in release mode; only useful for debug mode checking. class ConcurrencyState { - void *Mutex; // a llvm::sys::MutexImpl in debug; + void *Mutex; // a std::recursive_mutex in debug; public: ConcurrencyState(); diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index df0d6d4fe5..7e3f7a2f13 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -85,7 +85,6 @@ #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Mutex.h" #include "llvm/Support/Timer.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" @@ -96,6 +95,7 @@ #include #include #include +#include #include #include #include @@ -2692,20 +2692,20 @@ InputKind ASTUnit::getInputKind() const { #ifndef NDEBUG ASTUnit::ConcurrencyState::ConcurrencyState() { - Mutex = new llvm::sys::MutexImpl(/*recursive=*/true); + Mutex = new std::recursive_mutex; } ASTUnit::ConcurrencyState::~ConcurrencyState() { - delete static_cast(Mutex); + delete static_cast(Mutex); } void ASTUnit::ConcurrencyState::start() { - bool acquired = static_cast(Mutex)->tryacquire(); + bool acquired = static_cast(Mutex)->try_lock(); assert(acquired && "Concurrent access to ASTUnit!"); } void ASTUnit::ConcurrencyState::finish() { - static_cast(Mutex)->release(); + static_cast(Mutex)->unlock(); } #else // NDEBUG diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp index 36c0812205..1d30bbf605 100644 --- a/tools/libclang/Indexing.cpp +++ b/tools/libclang/Indexing.cpp @@ -28,7 +28,6 @@ #include "clang/Lex/PreprocessorOptions.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Mutex.h" #include #include #include @@ -122,22 +121,21 @@ namespace llvm { namespace { class SessionSkipBodyData { - llvm::sys::Mutex Mux; + std::mutex Mux; PPRegionSetTy ParsedRegions; public: - SessionSkipBodyData() : Mux(/*recursive=*/false) {} ~SessionSkipBodyData() { //llvm::errs() << "RegionData: " << Skipped.size() << " - " << Skipped.getMemorySize() << "\n"; } void copyTo(PPRegionSetTy &Set) { - std::lock_guard MG(Mux); + std::lock_guard MG(Mux); Set = ParsedRegions; } void update(ArrayRef Regions) { - std::lock_guard MG(Mux); + std::lock_guard MG(Mux); ParsedRegions.insert(Regions.begin(), Regions.end()); } };