Spin IncludeComplete's destructor until scanning completes (#147)

This commit is contained in:
Leszek Swirski 2018-12-04 18:28:40 +01:00 committed by Fangrui Song
parent d43b994557
commit 259b9fefb3
2 changed files with 7 additions and 0 deletions

View File

@ -102,6 +102,12 @@ CompletionItem BuildCompletionItem(const std::string &path,
IncludeComplete::IncludeComplete(Project *project) IncludeComplete::IncludeComplete(Project *project)
: is_scanning(false), project_(project) {} : is_scanning(false), project_(project) {}
IncludeComplete::~IncludeComplete() {
// Spin until the scanning has completed.
while (is_scanning.load())
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
void IncludeComplete::Rescan() { void IncludeComplete::Rescan() {
if (is_scanning || LLVM_VERSION_MAJOR >= 8) if (is_scanning || LLVM_VERSION_MAJOR >= 8)
return; return;

View File

@ -26,6 +26,7 @@ struct Project;
struct IncludeComplete { struct IncludeComplete {
IncludeComplete(Project *project); IncludeComplete(Project *project);
~IncludeComplete();
// Starts scanning directories. Clears existing cache. // Starts scanning directories. Clears existing cache.
void Rescan(); void Rescan();