Skip to content

Commit

Permalink
Remove LLVM mutexes from clang in favor of std::mutex
Browse files Browse the repository at this point in the history
None of those need to be recursive mutexes. No functionality change
intended.

llvm-svn: 368173
  • Loading branch information
d0k committed Aug 7, 2019
1 parent a06155d commit 762bc33
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Path.h"
#include <atomic>
#include <condition_variable>
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Frontend/PrecompiledPreamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <limits>
Expand Down Expand Up @@ -96,7 +95,7 @@ class TemporaryFiles {
void removeFile(StringRef File);

private:
llvm::sys::SmartMutex<false> Mutex;
std::mutex Mutex;
llvm::StringSet<> Files;
};

Expand All @@ -106,20 +105,20 @@ TemporaryFiles &TemporaryFiles::getInstance() {
}

TemporaryFiles::~TemporaryFiles() {
std::lock_guard<llvm::sys::Mutex> Guard(Mutex);
std::lock_guard<std::mutex> Guard(Mutex);
for (const auto &File : Files)
llvm::sys::fs::remove(File.getKey());
}

void TemporaryFiles::addFile(StringRef File) {
std::lock_guard<llvm::sys::Mutex> Guard(Mutex);
std::lock_guard<std::mutex> Guard(Mutex);
auto IsInserted = Files.insert(File).second;
(void)IsInserted;
assert(IsInserted && "File has already been added");
}

void TemporaryFiles::removeFile(StringRef File) {
std::lock_guard<llvm::sys::Mutex> Guard(Mutex);
std::lock_guard<std::mutex> Guard(Mutex);
auto WasPresent = Files.erase(File);
(void)WasPresent;
assert(WasPresent && "File was not tracked");
Expand Down
6 changes: 3 additions & 3 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include <mutex>

#if LLVM_ENABLE_THREADS != 0 && defined(__APPLE__)
#define USE_DARWIN_THREADS
Expand Down Expand Up @@ -8943,10 +8943,10 @@ Logger &cxindex::Logger::operator<<(const llvm::format_object_base &Fmt) {
return *this;
}

static llvm::ManagedStatic<llvm::sys::Mutex> LoggingMutex;
static llvm::ManagedStatic<std::mutex> LoggingMutex;

cxindex::Logger::~Logger() {
llvm::sys::ScopedLock L(*LoggingMutex);
std::lock_guard<std::mutex> L(*LoggingMutex);

static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();

Expand Down
1 change: 0 additions & 1 deletion clang/tools/libclang/CIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "clang-c/Index.h"
#include "clang/Frontend/PCHContainerOperations.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Mutex.h"
#include <utility>

namespace llvm {
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "clang/DirectoryWatcher/DirectoryWatcher.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
Expand Down

0 comments on commit 762bc33

Please sign in to comment.