diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 586002daef563c54e53aa825dfe5e62683e6ebd1..97e03266ebe06d1efb48cc91d4ee6443986c39c7 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -35,6 +35,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Diagnostic.h" #include "llvm/ADT/StringSet.h" +#include "llvm/Support/Atomic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Host.h" #include "llvm/Support/Path.h" @@ -85,7 +86,7 @@ const unsigned DefaultPreambleRebuildInterval = 5; /// \brief Tracks the number of ASTUnit objects that are currently active. /// /// Used for debugging purposes only. -static unsigned ActiveASTUnitObjects; +static llvm::sys::cas_flag ActiveASTUnitObjects; ASTUnit::ASTUnit(bool _MainFileIsAST) : CaptureDiagnostics(false), MainFileIsAST(_MainFileIsAST), @@ -98,7 +99,7 @@ ASTUnit::ASTUnit(bool _MainFileIsAST) CacheCodeCompletionCoolDown(0), UnsafeToFree(false) { if (getenv("LIBCLANG_OBJTRACKING")) { - ++ActiveASTUnitObjects; + llvm::sys::AtomicIncrement(&ActiveASTUnitObjects); fprintf(stderr, "+++ %d translation units\n", ActiveASTUnitObjects); } } @@ -129,7 +130,7 @@ ASTUnit::~ASTUnit() { ClearCachedCompletionResults(); if (getenv("LIBCLANG_OBJTRACKING")) { - --ActiveASTUnitObjects; + llvm::sys::AtomicDecrement(&ActiveASTUnitObjects); fprintf(stderr, "--- %d translation units\n", ActiveASTUnitObjects); } } diff --git a/clang/tools/libclang/CIndexCodeCompletion.cpp b/clang/tools/libclang/CIndexCodeCompletion.cpp index 7441f4fa1d03bd078e8a2b8ad8036fef8d5be57c..02e45052aba1c391cff66fe2a5e77e06722f9782 100644 --- a/clang/tools/libclang/CIndexCodeCompletion.cpp +++ b/clang/tools/libclang/CIndexCodeCompletion.cpp @@ -24,6 +24,7 @@ #include "clang/Sema/CodeCompleteConsumer.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/Atomic.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Timer.h" @@ -256,7 +257,7 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { /// currently active. /// /// Used for debugging purposes only. -static unsigned CodeCompletionResultObjects; +static llvm::sys::cas_flag CodeCompletionResultObjects; AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults() : CXCodeCompleteResults(), @@ -265,7 +266,7 @@ AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults() FileMgr(FileSystemOpts), SourceMgr(*Diag, FileMgr) { if (getenv("LIBCLANG_OBJTRACKING")) { - ++CodeCompletionResultObjects; + llvm::sys::AtomicIncrement(&CodeCompletionResultObjects); fprintf(stderr, "+++ %d completion results\n", CodeCompletionResultObjects); } } @@ -281,7 +282,7 @@ AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() { delete TemporaryBuffers[I]; if (getenv("LIBCLANG_OBJTRACKING")) { - --CodeCompletionResultObjects; + llvm::sys::AtomicDecrement(&CodeCompletionResultObjects); fprintf(stderr, "--- %d completion results\n", CodeCompletionResultObjects); } }