diff --git a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp index 6bcfb86e7f99..847d20bfbb6f 100644 --- a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp +++ b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp @@ -40,6 +40,7 @@ class DirectoryWatcherWindows : public clang::DirectoryWatcher { std::mutex Mutex; bool WatcherActive = false; + bool NotifierActive = false; std::condition_variable Ready; class EventQueue { @@ -117,7 +118,9 @@ DirectoryWatcherWindows::DirectoryWatcherWindows( }); std::unique_lock lock(Mutex); - Ready.wait(lock, [this] { return this->WatcherActive; }); + Ready.wait(lock, [this] { + return this->WatcherActive && this->NotifierActive; + }); } DirectoryWatcherWindows::~DirectoryWatcherWindows() { @@ -227,6 +230,12 @@ void DirectoryWatcherWindows::NotifierThreadProc(bool WaitForInitialSync) { if (!WaitForInitialSync) this->InitialScan(); + { + std::unique_lock lock(Mutex); + NotifierActive = true; + } + Ready.notify_one(); + while (true) { DirectoryWatcher::Event E = Q.pop_front(); Callback(E, /*IsInitial=*/false);