@@ -21,12 +21,6 @@ FILE_WATCHER::FILE_WATCHER() :
21
21
FALSE , // not set
22
22
nullptr ); // name
23
23
24
- m_pShutdownEvent = CreateEvent (
25
- nullptr , // default security attributes
26
- TRUE , // manual reset event
27
- FALSE , // not set
28
- nullptr ); // name
29
-
30
24
// Use of TerminateThread for the file watcher thread was eliminated in favor of an event-based
31
25
// approach. Out of an abundance of caution, we are temporarily adding an environment variable
32
26
// to allow falling back to TerminateThread usage. If all goes well, this will be removed in a
@@ -175,19 +169,8 @@ Win32 error
175
169
LOG_INFO (L" Starting file watcher thread" );
176
170
DBG_ASSERT (pFileMonitor != nullptr );
177
171
178
- HANDLE events[2 ] = { pFileMonitor->m_hCompletionPort , pFileMonitor->m_pShutdownEvent };
179
-
180
- DWORD dwEvent = 0 ;
181
172
while (true )
182
173
{
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
- }
191
174
192
175
DWORD cbCompletion = 0 ;
193
176
OVERLAPPED* pOverlapped = nullptr ;
@@ -203,6 +186,11 @@ Win32 error
203
186
DBG_ASSERT (success);
204
187
(void )success;
205
188
189
+ if (completionKey == FILE_WATCHER_SHUTDOWN_KEY)
190
+ {
191
+ break ;
192
+ }
193
+
206
194
DBG_ASSERT (pOverlapped != nullptr );
207
195
if (pOverlapped != nullptr )
208
196
{
@@ -469,7 +457,7 @@ FILE_WATCHER::StopMonitor()
469
457
LOG_INFO (L" Stopping file watching." );
470
458
471
459
// Signal the file watcher thread to exit
472
- SetEvent (m_pShutdownEvent );
460
+ PostQueuedCompletionStatus (m_hCompletionPort, 0 , FILE_WATCHER_SHUTDOWN_KEY, NULL );
473
461
WaitForWatcherThreadExit ();
474
462
475
463
if (m_fShadowCopyEnabled)
0 commit comments