]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
* [Bug 2472] (WinXP) Avoid self-termination of IO thread during exit().
authorJuergen Perlinger <perlinger@ntp.org>
Fri, 30 Aug 2013 19:23:39 +0000 (21:23 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Fri, 30 Aug 2013 19:23:39 +0000 (21:23 +0200)
bk: 5220f13bhMhQw4T_X9zzTHcEXVGZVA

ChangeLog
ports/winnt/ntpd/ntp_iocompletionport.c

index 9ebb9dc054c10c779068c069a32cd3027e5f0d90..43eaa5451777412c0ab11cee2b450e4e9519b18b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 2472] (WinXP) Avoid self-termination of IO thread during exit().
 (4.2.7p385) 2013/08/19 Released by Harlan Stenn <stenn@ntp.org>
 * CID 975596: Copy/paste error: vallen should be siglen.
 * CID 1009579: Check return status of X509_add_ext().
index ad35d5f52eb2436351001562b1bc642fb3585265..d1c3250569b810bd279a35bebbd7e8fbd50d65d9 100644 (file)
@@ -391,6 +391,7 @@ IoCtxReset(
  * -------------------------------------------------------------------
  */
 static HANDLE hIoCompletionThread;
+static UINT   tidCompletionThread;
 
 /*
  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -517,7 +518,7 @@ init_io_completion_port(void)
                iocompletionthread, 
                NULL, 
                0, 
-               NULL);
+               &tidCompletionThread);
 }
 
 
@@ -530,6 +531,8 @@ uninit_io_completion_port(
        void
        )
 {
+        DWORD rc;
+
        /* do noting if completion port already gone. */
        if (NULL == hIoCompletionPort)
                return;
@@ -538,17 +541,20 @@ uninit_io_completion_port(
         * Service thread seems running. Terminate him with grace
         * first and force later...
         */
-
-       /* post exit request for thread. */
-       PostQueuedCompletionStatus(hIoCompletionPort, 0, 0, 0);
-       IoCtxPoolDone(); /* stop using the memory pool */
-
-       if (WAIT_TIMEOUT == WaitForSingleObject(hIoCompletionThread, 5000)) {
-               /* Everything is lost. Kill off with TerminateThread. */
-               msyslog(LOG_ERR, "IO completion thread refuses to terminate");
-               TerminateThread(hIoCompletionThread, ~0UL);
+        if (tidCompletionThread != GetCurrentThreadId()) {
+               PostQueuedCompletionStatus(hIoCompletionPort, 0, 0, 0);
+                rc = WaitForSingleObject(hIoCompletionThread, 5000);
+                if (rc == WAIT_TIMEOUT) {
+                       /* Thread lost. Kill off with TerminateThread. */
+                       msyslog(LOG_ERR,
+                                "IO completion thread refuses to terminate");
+                       TerminateThread(hIoCompletionThread, ~0UL);
+                }
        }
 
+         /* stop using the memory pool */
+       IoCtxPoolDone();
+
        /* now reap all handles... */
        CloseHandle(hIoCompletionThread);
        hIoCompletionThread = NULL;