[clang] a6948da - DirectoryWatcher: close a possible window of race on Windows

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 15 09:15:58 PDT 2021


Author: Saleem Abdulrasool
Date: 2021-06-15T09:15:17-07:00
New Revision: a6948da86ad7e78d66b26263c2681ef6385cc234

URL: https://github.com/llvm/llvm-project/commit/a6948da86ad7e78d66b26263c2681ef6385cc234
DIFF: https://github.com/llvm/llvm-project/commit/a6948da86ad7e78d66b26263c2681ef6385cc234.diff

LOG: DirectoryWatcher: close a possible window of race on Windows

The initial scan occurring before the watcher is ready allows a race
condition where a change occurs before the initial scan completes.
Ensure that we wait for the watcher to begin executing the initial scan.

Addresses some feedback from Adrian McCarthy in post-commit review.

Added: 
    

Modified: 
    clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
index 847d20bfbb6f..8a4f5a87d967 100644
--- a/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
+++ b/clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp
@@ -133,6 +133,9 @@ DirectoryWatcherWindows::~DirectoryWatcherWindows() {
 }
 
 void DirectoryWatcherWindows::InitialScan() {
+  std::unique_lock<std::mutex> lock(Mutex);
+  Ready.wait(lock, [this] { return this->WatcherActive; });
+
   Callback(getAsFileEvents(scanDirectory(Path.data())), /*IsInitial=*/true);
 }
 


        


More information about the cfe-commits mailing list