Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang-tools-extra/clangd/TUScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ class PreambleThread {
}

{
// Add a lock guard to protect the critical section.
std::lock_guard<std::mutex> Lock(Mutex);
WithContext Guard(std::move(CurrentReq->Ctx));
// Note that we don't make use of the ContextProvider here.
// Preamble tasks are always scheduled by ASTWorker tasks, and we
Expand Down Expand Up @@ -1329,6 +1331,8 @@ void ASTWorker::startTask(llvm::StringRef Name,
std::optional<UpdateType> Update,
TUScheduler::ASTActionInvalidation Invalidation) {
if (RunSync) {
// Add a lock guard to protect the critical section.
std::lock_guard<std::mutex> Lock(Mutex);
assert(!Done && "running a task after stop()");
runTask(Name, Task);
return;
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/clangd/index/BackgroundRebuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ bool BackgroundIndexRebuilder::enoughTUsToRebuild() const {

void BackgroundIndexRebuilder::indexedTU() {
maybeRebuild("after indexing enough files", [this] {
// Add a lock guard to protect the critical section
std::lock_guard<std::mutex> Lock(Mu);
++IndexedTUs;
if (Loading)
return false; // rebuild once loading finishes
Expand Down Expand Up @@ -64,6 +66,8 @@ void BackgroundIndexRebuilder::loadedShard(size_t ShardCount) {
}
void BackgroundIndexRebuilder::doneLoading() {
maybeRebuild("after loading index from disk", [this] {
// Add a lock guard to protect the critical section.
std::lock_guard<std::mutex> Lock(Mu);
assert(Loading);
--Loading;
if (Loading) // was loading multiple batches concurrently
Expand Down