summaryrefslogtreecommitdiff
path: root/tools/libclang
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2019-09-05 09:48:39 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2019-09-05 09:48:39 +0000
commite4bd363824be0af8b009f63f074e6f3179d1dfb7 (patch)
tree854988d7b74be37fcda260e779c896cf7830dc61 /tools/libclang
parent88d5d4225c72d47a5979edfbabff0df87543c04d (diff)
downloadclang-e4bd363824be0af8b009f63f074e6f3179d1dfb7.tar.gz
[libclang] Refactored SharedParsedRegionsStorage
Summary: Removed the `PPRegionSetTy` typedef because it is only used 3 times, and obscures code more than it helps. Renamed SharedParsedRegionsStorage to ThreadSafeParsedRegions, because that better reflects the reason for this type to exist. Replaced the `copyTo()` method that had an out parameter with a getter. Renamed the `merge()` method to `addParsedRegions()`. Renamed `ParsedSrcLocationsTracker::ParsedRegions` to `ParsedRegionsSnapshot`, which better reflects its role. Subscribers: arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67077 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@371041 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang')
-rw-r--r--tools/libclang/Indexing.cpp47
1 files changed, 23 insertions, 24 deletions
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 5e567b3276..75b83d73d1 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -88,8 +88,6 @@ public:
}
};
-typedef llvm::DenseSet<PPRegion> PPRegionSetTy;
-
} // end anonymous namespace
namespace llvm {
@@ -124,20 +122,20 @@ namespace {
/// Keeps track of function bodies that have already been parsed.
///
/// Is thread-safe.
-class SharedParsedRegionsStorage {
- std::mutex Mux;
- PPRegionSetTy ParsedRegions;
+class ThreadSafeParsedRegions {
+ mutable std::mutex Mutex;
+ llvm::DenseSet<PPRegion> ParsedRegions;
public:
- ~SharedParsedRegionsStorage() = default;
+ ~ThreadSafeParsedRegions() = default;
- void copyTo(PPRegionSetTy &Set) {
- std::lock_guard<std::mutex> MG(Mux);
- Set = ParsedRegions;
+ llvm::DenseSet<PPRegion> getParsedRegions() const {
+ std::lock_guard<std::mutex> MG(Mutex);
+ return ParsedRegions;
}
- void merge(ArrayRef<PPRegion> Regions) {
- std::lock_guard<std::mutex> MG(Mux);
+ void addParsedRegions(ArrayRef<PPRegion> Regions) {
+ std::lock_guard<std::mutex> MG(Mutex);
ParsedRegions.insert(Regions.begin(), Regions.end());
}
};
@@ -147,13 +145,13 @@ public:
///
/// Is NOT thread-safe.
class ParsedSrcLocationsTracker {
- SharedParsedRegionsStorage &ParsedRegionsStorage;
+ ThreadSafeParsedRegions &ParsedRegionsStorage;
PPConditionalDirectiveRecord &PPRec;
Preprocessor &PP;
/// Snapshot of the shared state at the point when this instance was
/// constructed.
- PPRegionSetTy ParsedRegions;
+ llvm::DenseSet<PPRegion> ParsedRegionsSnapshot;
/// Regions that were queried during this instance lifetime.
SmallVector<PPRegion, 32> NewParsedRegions;
@@ -163,12 +161,11 @@ class ParsedSrcLocationsTracker {
public:
/// Creates snapshot of \p ParsedRegionsStorage.
- ParsedSrcLocationsTracker(SharedParsedRegionsStorage &ParsedRegionsStorage,
+ ParsedSrcLocationsTracker(ThreadSafeParsedRegions &ParsedRegionsStorage,
PPConditionalDirectiveRecord &ppRec,
Preprocessor &pp)
- : ParsedRegionsStorage(ParsedRegionsStorage), PPRec(ppRec), PP(pp) {
- ParsedRegionsStorage.copyTo(ParsedRegions);
- }
+ : ParsedRegionsStorage(ParsedRegionsStorage), PPRec(ppRec), PP(pp),
+ ParsedRegionsSnapshot(ParsedRegionsStorage.getParsedRegions()) {}
/// \returns true iff \p Loc has already been parsed.
///
@@ -190,14 +187,16 @@ public:
// That means if we hit the same region again, it's a different location in
// the same region and so the "is parsed" value from the snapshot is still
// correct.
- LastIsParsed = ParsedRegions.count(region);
+ LastIsParsed = ParsedRegionsSnapshot.count(region);
if (!LastIsParsed)
NewParsedRegions.emplace_back(std::move(region));
return LastIsParsed;
}
/// Updates ParsedRegionsStorage with newly parsed regions.
- void syncWithStorage() { ParsedRegionsStorage.merge(NewParsedRegions); }
+ void syncWithStorage() {
+ ParsedRegionsStorage.addParsedRegions(NewParsedRegions);
+ }
private:
PPRegion getRegion(SourceLocation Loc, FileID FID, const FileEntry *FE) {
@@ -336,13 +335,13 @@ class IndexingFrontendAction : public ASTFrontendAction {
std::shared_ptr<CXIndexDataConsumer> DataConsumer;
IndexingOptions Opts;
- SharedParsedRegionsStorage *SKData;
+ ThreadSafeParsedRegions *SKData;
std::unique_ptr<ParsedSrcLocationsTracker> ParsedLocsTracker;
public:
IndexingFrontendAction(std::shared_ptr<CXIndexDataConsumer> dataConsumer,
const IndexingOptions &Opts,
- SharedParsedRegionsStorage *skData)
+ ThreadSafeParsedRegions *skData)
: DataConsumer(std::move(dataConsumer)), Opts(Opts), SKData(skData) {}
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
@@ -431,10 +430,10 @@ static IndexingOptions getIndexingOptionsFromCXOptions(unsigned index_options) {
struct IndexSessionData {
CXIndex CIdx;
- std::unique_ptr<SharedParsedRegionsStorage> SkipBodyData;
+ std::unique_ptr<ThreadSafeParsedRegions> SkipBodyData =
+ std::make_unique<ThreadSafeParsedRegions>();
- explicit IndexSessionData(CXIndex cIdx)
- : CIdx(cIdx), SkipBodyData(new SharedParsedRegionsStorage) {}
+ explicit IndexSessionData(CXIndex cIdx) : CIdx(cIdx) {}
};
} // anonymous namespace