9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_H 22 #include "clang/Tooling/CompilationDatabase.h" 23 #include "llvm/ADT/StringMap.h" 24 #include "llvm/Support/Threading.h" 26 #include <condition_variable> 50 virtual std::unique_ptr<IndexFileIn>
51 loadShard(llvm::StringRef ShardIdentifier)
const = 0;
56 using Factory = llvm::unique_function<BackgroundIndexStorage *(PathRef)>;
63 std::function<llvm::Optional<ProjectInfo>(
PathRef)> GetProjectInfo);
71 explicit Task(std::function<
void()> Run) : Run(std::move(Run)) {}
73 std::function<void()>
Run;
74 llvm::ThreadPriority ThreadPri = llvm::ThreadPriority::Background;
75 unsigned QueuePri = 0;
83 void append(std::vector<Task>);
87 void boost(llvm::StringRef
Tag,
unsigned NewPriority);
91 void work(std::function<
void()> OnIdle =
nullptr);
98 static void preventThreadStarvationInTests();
100 blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds);
104 unsigned NumActiveTasks = 0;
105 std::condition_variable CV;
106 bool ShouldStop =
false;
107 std::vector<Task> Queue;
108 llvm::StringMap<unsigned> Boosts;
124 size_t ThreadPoolSize = llvm::heavyweight_hardware_concurrency());
130 void enqueue(
const std::vector<std::string> &ChangedFiles) {
131 Queue.push(changedFilesTask(ChangedFiles));
136 void boostRelated(llvm::StringRef
Path);
141 Rebuilder.shutdown();
148 return Queue.blockUntilIdleForTest(TimeoutSeconds);
153 struct ShardVersion {
155 bool HadErrors =
false;
162 const llvm::StringMap<ShardVersion> &ShardVersionsSnapshot,
174 llvm::StringMap<ShardVersion> ShardVersions;
175 std::mutex ShardVersionsMu;
179 std::vector<tooling::CompileCommand>
180 loadProject(std::vector<std::string> MainFiles);
183 changedFilesTask(
const std::vector<std::string> &ChangedFiles);
194 GlobalCompilationDatabase::CommandChanged::Subscription CommandsChanged;
llvm::unique_function< BackgroundIndexStorage *(PathRef)> Factory
std::array< uint8_t, 8 > FileDigest
A container of Symbols from several source files.
static Factory createDiskBackedStorageFactory(std::function< llvm::Optional< ProjectInfo >(PathRef)> GetProjectInfo)
llvm::StringRef PathRef
A typedef to represent a ref to file path.
std::function< void()> Run
bool operator<(const Task &O) const
MockFSProvider FSProvider
Provides compilation arguments used for parsing C and C++ files.
std::string Path
A typedef to represent a file path.
void enqueue(const std::vector< std::string > &ChangedFiles)
Runs tasks on separate (detached) threads and wait for all tasks to finish.
A context is an immutable container for per-request data that must be propagated through layers that ...
virtual std::unique_ptr< IndexFileIn > loadShard(llvm::StringRef ShardIdentifier) const =0
virtual llvm::Error storeShard(llvm::StringRef ShardIdentifier, IndexFileOut Shard) const =0
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
LLVM_NODISCARD bool blockUntilIdleForTest(llvm::Optional< double > TimeoutSeconds=10)
Task(std::function< void()> Run)
virtual ~BackgroundIndexStorage()=default
A work item on the thread pool's queue.
const SymbolIndex * Index