Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ FILE_WATCHER::FILE_WATCHER() :
FALSE, // not set
nullptr); // name

m_pShutdownEvent = CreateEvent(
nullptr, // default security attributes
TRUE, // manual reset event
FALSE, // not set
nullptr); // name

// Use of TerminateThread for the file watcher thread was eliminated in favor of an event-based
// approach. Out of an abundance of caution, we are temporarily adding an environment variable
// to allow falling back to TerminateThread usage. If all goes well, this will be removed in a
Expand Down Expand Up @@ -175,19 +169,8 @@ Win32 error
LOG_INFO(L"Starting file watcher thread");
DBG_ASSERT(pFileMonitor != nullptr);

HANDLE events[2] = { pFileMonitor->m_hCompletionPort, pFileMonitor->m_pShutdownEvent };

DWORD dwEvent = 0;
while (true)
{
// Wait for either a change notification or a shutdown event.
dwEvent = WaitForMultipleObjects(ARRAYSIZE(events), events, FALSE, INFINITE) - WAIT_OBJECT_0;

if (dwEvent == 1)
{
// Shutdown event.
break;
}

DWORD cbCompletion = 0;
OVERLAPPED* pOverlapped = nullptr;
Expand All @@ -203,6 +186,11 @@ Win32 error
DBG_ASSERT(success);
(void)success;

if (completionKey == FILE_WATCHER_SHUTDOWN_KEY)
{
break;
}

DBG_ASSERT(pOverlapped != nullptr);
if (pOverlapped != nullptr)
{
Expand Down Expand Up @@ -469,7 +457,7 @@ FILE_WATCHER::StopMonitor()
LOG_INFO(L"Stopping file watching.");

// Signal the file watcher thread to exit
SetEvent(m_pShutdownEvent);
PostQueuedCompletionStatus(m_hCompletionPort, 0, FILE_WATCHER_SHUTDOWN_KEY, NULL);
WaitForWatcherThreadExit();

if (m_fShadowCopyEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class FILE_WATCHER{
HandleWrapper<NullHandleTraits> m_hChangeNotificationThread;
HandleWrapper<NullHandleTraits> _hDirectory;
HandleWrapper<NullHandleTraits> m_pDoneCopyEvent;
HandleWrapper<NullHandleTraits> m_pShutdownEvent;
std::atomic_bool m_fThreadExit;
STTIMER m_Timer;
SRWLOCK m_copyLock{};
Expand Down