From 3135d45300e4381f077847912be989c3e94f930e Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 2 Mar 2014 17:08:31 +0000 Subject: [PATCH] [C++11] Use std::atomic instead of LLVM's. No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202652 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/VirtualFileSystem.cpp | 6 +++--- lib/Frontend/ASTUnit.cpp | 16 ++++++---------- lib/Frontend/CompilerInvocation.cpp | 6 +++--- tools/libclang/CIndexCodeCompletion.cpp | 18 ++++++++---------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/Basic/VirtualFileSystem.cpp b/lib/Basic/VirtualFileSystem.cpp index 73d6e7f7b2..43b203a334 100644 --- a/lib/Basic/VirtualFileSystem.cpp +++ b/lib/Basic/VirtualFileSystem.cpp @@ -14,10 +14,10 @@ #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/Atomic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/YAMLParser.h" +#include using namespace clang; using namespace clang::vfs; @@ -828,8 +828,8 @@ vfs::getVFSFromYAML(MemoryBuffer *Buffer, SourceMgr::DiagHandlerTy DiagHandler, } UniqueID vfs::getNextVirtualUniqueID() { - static volatile sys::cas_flag UID = 0; - sys::cas_flag ID = llvm::sys::AtomicIncrement(&UID); + static std::atomic UID; + unsigned ID = ++UID; // The following assumes that uint64_t max will never collide with a real // dev_t value from the OS. return UniqueID(std::numeric_limits::max(), ID); diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 913bbc77dd..cbdfa33453 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -36,7 +36,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" -#include "llvm/Support/Atomic.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/Host.h" #include "llvm/Support/MemoryBuffer.h" @@ -45,6 +44,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" +#include #include #include #include @@ -211,7 +211,7 @@ const unsigned DefaultPreambleRebuildInterval = 5; /// \brief Tracks the number of ASTUnit objects that are currently active. /// /// Used for debugging purposes only. -static llvm::sys::cas_flag ActiveASTUnitObjects; +static std::atomic ActiveASTUnitObjects; ASTUnit::ASTUnit(bool _MainFileIsAST) : Reader(0), HadModuleLoaderFatalFailure(false), @@ -228,10 +228,8 @@ ASTUnit::ASTUnit(bool _MainFileIsAST) PreambleTopLevelHashValue(0), CurrentTopLevelHashValue(0), UnsafeToFree(false) { - if (getenv("LIBCLANG_OBJTRACKING")) { - llvm::sys::AtomicIncrement(&ActiveASTUnitObjects); - fprintf(stderr, "+++ %d translation units\n", (int)ActiveASTUnitObjects); - } + if (getenv("LIBCLANG_OBJTRACKING")) + fprintf(stderr, "+++ %u translation units\n", ++ActiveASTUnitObjects); } ASTUnit::~ASTUnit() { @@ -264,10 +262,8 @@ ASTUnit::~ASTUnit() { ClearCachedCompletionResults(); - if (getenv("LIBCLANG_OBJTRACKING")) { - llvm::sys::AtomicDecrement(&ActiveASTUnitObjects); - fprintf(stderr, "--- %d translation units\n", (int)ActiveASTUnitObjects); - } + if (getenv("LIBCLANG_OBJTRACKING")) + fprintf(stderr, "--- %u translation units\n", --ActiveASTUnitObjects); } void ASTUnit::setPreprocessor(Preprocessor *pp) { PP = pp; } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index c2571d716a..85aae236b8 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -28,13 +28,13 @@ #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" -#include "llvm/Support/Atomic.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/system_error.h" +#include #include using namespace clang; @@ -1883,8 +1883,8 @@ void BuryPointer(const void *Ptr) { // is what we want in such case. static const size_t kGraveYardMaxSize = 16; LLVM_ATTRIBUTE_UNUSED static const void *GraveYard[kGraveYardMaxSize]; - static llvm::sys::cas_flag GraveYardSize; - llvm::sys::cas_flag Idx = llvm::sys::AtomicIncrement(&GraveYardSize) - 1; + static std::atomic GraveYardSize; + unsigned Idx = GraveYardSize++; if (Idx >= kGraveYardMaxSize) return; GraveYard[Idx] = Ptr; diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index ca4960cc26..e13e3e18a2 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -30,13 +30,13 @@ #include "clang/Sema/Sema.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/Atomic.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Program.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" +#include #include #include #include @@ -315,7 +315,7 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { /// currently active. /// /// Used for debugging purposes only. -static llvm::sys::cas_flag CodeCompletionResultObjects; +static std::atomic CodeCompletionResultObjects; AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults( const FileSystemOptions& FileSystemOpts) @@ -332,10 +332,9 @@ AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults( ContainerKind(CXCursor_InvalidCode), ContainerIsIncomplete(1) { - if (getenv("LIBCLANG_OBJTRACKING")) { - llvm::sys::AtomicIncrement(&CodeCompletionResultObjects); - fprintf(stderr, "+++ %d completion results\n", CodeCompletionResultObjects); - } + if (getenv("LIBCLANG_OBJTRACKING")) + fprintf(stderr, "+++ %u completion results\n", + ++CodeCompletionResultObjects); } AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() { @@ -346,10 +345,9 @@ AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() { for (unsigned I = 0, N = TemporaryBuffers.size(); I != N; ++I) delete TemporaryBuffers[I]; - if (getenv("LIBCLANG_OBJTRACKING")) { - llvm::sys::AtomicDecrement(&CodeCompletionResultObjects); - fprintf(stderr, "--- %d completion results\n", CodeCompletionResultObjects); - } + if (getenv("LIBCLANG_OBJTRACKING")) + fprintf(stderr, "--- %u completion results\n", + --CodeCompletionResultObjects); } } // end extern "C" -- 2.40.0