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;
163 void enqueue(
const std::vector<std::string> &ChangedFiles) {
164 Queue.
push(changedFilesTask(ChangedFiles));
188 struct ShardVersion {
190 bool HadErrors =
false;
196 void update(llvm::StringRef
MainFile, IndexFileIn Index,
197 const llvm::StringMap<ShardVersion> &ShardVersionsSnapshot,
201 const ThreadsafeFS &TFS;
202 const GlobalCompilationDatabase &CDB;
203 llvm::ThreadPriority IndexingPriority;
204 std::function<Context(
PathRef)> ContextProvider;
206 llvm::Error index(tooling::CompileCommand);
208 FileSymbols IndexedSymbols;
209 BackgroundIndexRebuilder Rebuilder;
210 llvm::StringMap<ShardVersion> ShardVersions;
211 std::mutex ShardVersionsMu;
215 std::vector<std::string> loadProject(std::vector<std::string> MainFiles);
217 BackgroundQueue::Task
218 changedFilesTask(
const std::vector<std::string> &ChangedFiles);
219 BackgroundQueue::Task indexFileTask(std::string
Path);
227 BackgroundQueue Queue;
228 AsyncTaskRunner ThreadPool;
229 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
bool SupportContainedRefs
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...