[SHELL32] Follow-up of #2659

Add CreateAPCThread function and use it. CORE-13950
This commit is contained in:
Katayama Hirofumi MZ 2020-05-04 15:28:16 +09:00
parent 5c589b5537
commit 7980f40911

View file

@ -787,6 +787,17 @@ void CChangeNotifyServer::RemoveItemsByProcess(DWORD dwOwnerPID, DWORD dwUserPID
} }
} }
BOOL CreateAPCThread(void)
{
if (s_hThreadAPC != NULL)
return TRUE;
unsigned tid;
s_fTerminateAllWatches = FALSE;
s_hThreadAPC = (HANDLE)_beginthreadex(NULL, 0, DirWatchThreadFuncAPC, NULL, 0, &tid);
return s_hThreadAPC != NULL;
}
// Message CN_REGISTER: Register the registration entry. // Message CN_REGISTER: Register the registration entry.
// wParam: The handle of registration entry. // wParam: The handle of registration entry.
// lParam: The owner PID of registration entry. // lParam: The owner PID of registration entry.
@ -834,19 +845,13 @@ LRESULT CChangeNotifyServer::OnRegister(UINT uMsg, WPARAM wParam, LPARAM lParam,
if (pDirWatch) if (pDirWatch)
{ {
// create an APC thread for directory watching // create an APC thread for directory watching
if (s_hThreadAPC == NULL) if (!CreateAPCThread())
{
unsigned tid;
s_fTerminateAllWatches = FALSE;
s_hThreadAPC = (HANDLE)_beginthreadex(NULL, 0, DirWatchThreadFuncAPC, NULL, 0, &tid);
if (s_hThreadAPC == NULL)
{ {
pRegEntry->nRegID = INVALID_REG_ID; pRegEntry->nRegID = INVALID_REG_ID;
SHUnlockShared(pRegEntry); SHUnlockShared(pRegEntry);
delete pDirWatch; delete pDirWatch;
return FALSE; return FALSE;
} }
}
// request adding the watch // request adding the watch
QueueUserAPC(_AddDirectoryProcAPC, s_hThreadAPC, (ULONG_PTR)pDirWatch); QueueUserAPC(_AddDirectoryProcAPC, s_hThreadAPC, (ULONG_PTR)pDirWatch);