From 25c892812178e61ffa1b1d6f419e286ba18235b6 Mon Sep 17 00:00:00 2001 From: Leszek Swirski Date: Tue, 4 Dec 2018 18:28:40 +0100 Subject: [PATCH] Spin IncludeComplete's destructor until scanning completes (#147) --- src/include_complete.cc | 6 ++++++ src/include_complete.hh | 1 + 2 files changed, 7 insertions(+) diff --git a/src/include_complete.cc b/src/include_complete.cc index a07d66d3..6090233a 100644 --- a/src/include_complete.cc +++ b/src/include_complete.cc @@ -90,6 +90,12 @@ CompletionItem BuildCompletionItem(const std::string &path, IncludeComplete::IncludeComplete(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() { if (is_scanning || LLVM_VERSION_MAJOR >= 8) return; diff --git a/src/include_complete.hh b/src/include_complete.hh index 7e810c4f..b9d02bae 100644 --- a/src/include_complete.hh +++ b/src/include_complete.hh @@ -14,6 +14,7 @@ struct Project; struct IncludeComplete { IncludeComplete(Project *project); + ~IncludeComplete(); // Starts scanning directories. Clears existing cache. void Rescan();