9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_H
23#include "clang/Tooling/CompilationDatabase.h"
24#include "llvm/ADT/StringMap.h"
25#include "llvm/Support/Threading.h"
27#include <condition_variable>
47 virtual llvm::Error
storeShard(llvm::StringRef ShardIdentifier,
52 virtual std::unique_ptr<IndexFileIn>
53 loadShard(llvm::StringRef ShardIdentifier)
const = 0;
65 std::function<std::optional<ProjectInfo>(
PathRef)> GetProjectInfo);
75 std::function<void()>
Run;
76 llvm::ThreadPriority
ThreadPri = llvm::ThreadPriority::Low;
94 : OnProgress(OnProgress) {}
98 void append(std::vector<Task>);
102 void boost(llvm::StringRef
Tag,
unsigned NewPriority);
106 void work(std::function<
void()> OnIdle =
nullptr);
118 void notifyProgress()
const;
119 bool adjust(Task &T);
123 std::condition_variable CV;
124 bool ShouldStop =
false;
125 std::vector<Task> Queue;
126 llvm::StringMap<unsigned> Boosts;
127 std::function<void(Stats)> OnProgress;
128 llvm::DenseSet<uint64_t> SeenKeys;
160 void enqueue(
const std::vector<std::string> &ChangedFiles) {
161 Queue.
push(changedFilesTask(ChangedFiles));
185 struct ShardVersion {
187 bool HadErrors =
false;
193 void update(llvm::StringRef
MainFile, IndexFileIn Index,
194 const llvm::StringMap<ShardVersion> &ShardVersionsSnapshot,
198 const ThreadsafeFS &TFS;
199 const GlobalCompilationDatabase &CDB;
200 llvm::ThreadPriority IndexingPriority;
201 std::function<Context(
PathRef)> ContextProvider;
203 llvm::Error index(tooling::CompileCommand);
205 FileSymbols IndexedSymbols;
206 BackgroundIndexRebuilder Rebuilder;
207 llvm::StringMap<ShardVersion> ShardVersions;
208 std::mutex ShardVersionsMu;
212 std::vector<std::string> loadProject(std::vector<std::string> MainFiles);
214 BackgroundQueue::Task
215 changedFilesTask(
const std::vector<std::string> &ChangedFiles);
216 BackgroundQueue::Task indexFileTask(std::string
Path);
224 BackgroundQueue Queue;
225 AsyncTaskRunner ThreadPool;
226 GlobalCompilationDatabase::CommandChanged::Subscription CommandsChanged;
virtual llvm::Error storeShard(llvm::StringRef ShardIdentifier, IndexFileOut Shard) const =0
llvm::unique_function< BackgroundIndexStorage *(PathRef)> Factory
virtual ~BackgroundIndexStorage()=default
static Factory createDiskBackedStorageFactory(std::function< std::optional< ProjectInfo >(PathRef)> GetProjectInfo)
virtual std::unique_ptr< IndexFileIn > loadShard(llvm::StringRef ShardIdentifier) const =0
void profile(MemoryTree &MT) const
bool blockUntilIdleForTest(std::optional< double > TimeoutSeconds=10)
void boostRelated(llvm::StringRef Path)
Boosts priority of indexing related to Path.
void enqueue(const std::vector< std::string > &ChangedFiles)
static void preventThreadStarvationInTests()
bool blockUntilIdleForTest(std::optional< double > TimeoutSeconds)
void work(std::function< void()> OnIdle=nullptr)
BackgroundQueue(std::function< void(Stats)> OnProgress=nullptr)
void boost(llvm::StringRef Tag, unsigned NewPriority)
A context is an immutable container for per-request data that must be propagated through layers that ...
Provides compilation arguments used for parsing C and C++ files.
Values in a Context are indexed by typed keys.
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
std::string Path
A typedef to represent a file path.
std::array< uint8_t, 8 > FileDigest
llvm::StringRef PathRef
A typedef to represent a ref to file path.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::ThreadPriority IndexingPriority
std::function< Context(PathRef)> ContextProvider
std::function< void(BackgroundQueue::Stats)> OnProgress
A work item on the thread pool's queue.
std::function< void()> Run
bool operator<(const Task &O) const
llvm::ThreadPriority ThreadPri
Task(std::function< void()> Run)
A tree that can be used to represent memory usage of nested components while preserving the hierarchy...