16#include <condition_variable>
28bool BackgroundIndexRebuilder::enoughTUsToRebuild()
const {
36 maybeRebuild(
"after indexing enough files", [
this] {
40 if (ActiveVersion != StartedVersion)
42 return enoughTUsToRebuild();
47 maybeRebuild(
"when background indexer is idle", [
this] {
50 return IndexedTUs > IndexedTUsAtLastRebuild;
55 std::lock_guard<std::mutex> Lock(Mu);
61 std::lock_guard<std::mutex> Lock(Mu);
63 LoadedShards += ShardCount;
66 maybeRebuild(
"after loading index from disk", [
this] {
72 return LoadedShards > 0 || enoughTUsToRebuild();
77 std::lock_guard<std::mutex> Lock(Mu);
81void BackgroundIndexRebuilder::maybeRebuild(
const char *Reason,
82 std::function<
bool()> Check) {
83 unsigned BuildVersion = 0;
85 std::lock_guard<std::mutex> Lock(Mu);
86 if (!ShouldStop && Check()) {
87 BuildVersion = ++StartedVersion;
88 IndexedTUsAtLastRebuild = IndexedTUs;
92 std::unique_ptr<SymbolIndex> NewIndex;
94 vlog(
"BackgroundIndex: building version {0} {1}", BuildVersion, Reason);
95 trace::Span Tracer(
"RebuildBackgroundIndex");
100 std::lock_guard<std::mutex> Lock(Mu);
102 if (BuildVersion > ActiveVersion) {
103 ActiveVersion = BuildVersion;
104 vlog(
"BackgroundIndex: serving version {0} ({1} bytes)", BuildVersion,
105 NewIndex->estimateMemoryUsage());
106 Target->
reset(std::move(NewIndex));
#define SPAN_ATTACH(S, Name, Expr)
Attach a key-value pair to a Span event.
void loadedShard(size_t ShardCount)
const unsigned TUsBeforeFirstBuild
const unsigned TUsBeforeRebuild
std::unique_ptr< SymbolIndex > buildIndex(IndexType, DuplicateHandling DuplicateHandle=DuplicateHandling::PickOne, size_t *Version=nullptr)
The index keeps the slabs alive.
void reset(std::unique_ptr< SymbolIndex >)
void vlog(const char *Fmt, Ts &&... Vals)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//