@@ -21,12 +21,6 @@ FILE_WATCHER::FILE_WATCHER() :
2121 FALSE , // not set
2222 nullptr ); // name
2323
24- m_pShutdownEvent = CreateEvent (
25- nullptr , // default security attributes
26- TRUE , // manual reset event
27- FALSE , // not set
28- nullptr ); // name
29-
3024 // Use of TerminateThread for the file watcher thread was eliminated in favor of an event-based
3125 // approach. Out of an abundance of caution, we are temporarily adding an environment variable
3226 // to allow falling back to TerminateThread usage. If all goes well, this will be removed in a
@@ -175,19 +169,8 @@ Win32 error
175169 LOG_INFO (L" Starting file watcher thread" );
176170 DBG_ASSERT (pFileMonitor != nullptr );
177171
178- HANDLE events[2 ] = { pFileMonitor->m_hCompletionPort , pFileMonitor->m_pShutdownEvent };
179-
180- DWORD dwEvent = 0 ;
181172 while (true )
182173 {
183- // Wait for either a change notification or a shutdown event.
184- dwEvent = WaitForMultipleObjects (ARRAYSIZE (events), events, FALSE , INFINITE) - WAIT_OBJECT_0;
185-
186- if (dwEvent == 1 )
187- {
188- // Shutdown event.
189- break ;
190- }
191174
192175 DWORD cbCompletion = 0 ;
193176 OVERLAPPED* pOverlapped = nullptr ;
@@ -203,6 +186,11 @@ Win32 error
203186 DBG_ASSERT (success);
204187 (void )success;
205188
189+ if (completionKey == FILE_WATCHER_SHUTDOWN_KEY)
190+ {
191+ break ;
192+ }
193+
206194 DBG_ASSERT (pOverlapped != nullptr );
207195 if (pOverlapped != nullptr )
208196 {
@@ -469,7 +457,7 @@ FILE_WATCHER::StopMonitor()
469457 LOG_INFO (L" Stopping file watching." );
470458
471459 // Signal the file watcher thread to exit
472- SetEvent (m_pShutdownEvent );
460+ PostQueuedCompletionStatus (m_hCompletionPort, 0 , FILE_WATCHER_SHUTDOWN_KEY, NULL );
473461 WaitForWatcherThreadExit ();
474462
475463 if (m_fShadowCopyEnabled)
0 commit comments