* -------------------------------------------------------------------
*/
static HANDLE hIoCompletionThread;
+static UINT tidCompletionThread;
/*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
iocompletionthread,
NULL,
0,
- NULL);
+ &tidCompletionThread);
}
void
)
{
+ DWORD rc;
+
/* do noting if completion port already gone. */
if (NULL == hIoCompletionPort)
return;
* 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;