https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7980f409112cdc87890e90f9836ae52c6c3f8b76

commit 7980f409112cdc87890e90f9836ae52c6c3f8b76
Author:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
AuthorDate: Mon May 4 15:28:16 2020 +0900
Commit:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
CommitDate: Mon May 4 15:28:16 2020 +0900

    [SHELL32] Follow-up of #2659
    
    Add CreateAPCThread function and use it. CORE-13950
---
 .../shell32/shelldesktop/CChangeNotifyServer.cpp   | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/dll/win32/shell32/shelldesktop/CChangeNotifyServer.cpp 
b/dll/win32/shell32/shelldesktop/CChangeNotifyServer.cpp
index a5852976f1e..da619b9104b 100644
--- a/dll/win32/shell32/shelldesktop/CChangeNotifyServer.cpp
+++ b/dll/win32/shell32/shelldesktop/CChangeNotifyServer.cpp
@@ -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.
 //   wParam: The handle of registration entry.
 //   lParam: The owner PID of registration entry.
@@ -834,18 +845,12 @@ LRESULT CChangeNotifyServer::OnRegister(UINT uMsg, WPARAM 
wParam, LPARAM lParam,
     if (pDirWatch)
     {
         // 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;
-                SHUnlockShared(pRegEntry);
-                delete pDirWatch;
-                return FALSE;
-            }
+            pRegEntry->nRegID = INVALID_REG_ID;
+            SHUnlockShared(pRegEntry);
+            delete pDirWatch;
+            return FALSE;
         }
 
         // request adding the watch

Reply via email to