diff options
author | sebres <sebres@users.sourceforge.net> | 2017-05-03 10:20:03 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-05-03 10:20:03 (GMT) |
commit | 5ef04d196e88448151961a9e846243e002560031 (patch) | |
tree | 09d595633875058f5daa513f2c715fc33a6ae3fe | |
parent | 3dd348e3693ea3a0e5b01646d0fe726bf21b9c8f (diff) | |
download | tcl-5ef04d196e88448151961a9e846243e002560031.zip tcl-5ef04d196e88448151961a9e846243e002560031.tar.gz tcl-5ef04d196e88448151961a9e846243e002560031.tar.bz2 |
[win] Ensure nothing calls CreateThread directly, may cause conflicts when using the CRT library resp. libraries with static TLS.
Rewritten using new TclWinThreadCreate (call TclWinThreadExit added at end of corresponding thread proc).
-rw-r--r-- | win/tclWinSock.c | 31 | ||||
-rw-r--r-- | win/tclWinTime.c | 8 |
2 files changed, 23 insertions, 16 deletions
diff --git a/win/tclWinSock.c b/win/tclWinSock.c index 8f565b9..c5cc224 100644 --- a/win/tclWinSock.c +++ b/win/tclWinSock.c @@ -262,7 +262,6 @@ static Tcl_ChannelType tcpChannelType = { static void InitSockets(void) { - DWORD id; ThreadSpecificData *tsdPtr = (ThreadSpecificData *) TclThreadDataKeyGet(&dataKey); @@ -313,8 +312,8 @@ InitSockets(void) if (tsdPtr->socketListLock == NULL) { goto initFailure; } - tsdPtr->socketThread = CreateThread(NULL, 256, SocketThread, tsdPtr, - 0, &id); + tsdPtr->socketThread = TclWinThreadCreate(NULL, SocketThread, tsdPtr, + 256); if (tsdPtr->socketThread == NULL) { goto initFailure; } @@ -432,17 +431,20 @@ TclpFinalizeSockets(void) if (tsdPtr != NULL) { if (tsdPtr->socketThread != NULL) { if (tsdPtr->hwnd != NULL) { - if (PostMessage(tsdPtr->hwnd, SOCKET_TERMINATE, 0, 0)) { - /* - * Wait for the thread to exit. This ensures that we are - * completely cleaned up before we leave this function. - */ - WaitForSingleObject(tsdPtr->readyEvent, INFINITE); - } + PostMessage(tsdPtr->hwnd, SOCKET_TERMINATE, 0, 0); tsdPtr->hwnd = NULL; } - CloseHandle(tsdPtr->socketThread); - tsdPtr->socketThread = NULL; + /* + * Wait for the thread to exit. This ensures that we are + * completely cleaned up before we leave this function. + */ + if (tsdPtr->socketThread) { + WaitForSingleObject(tsdPtr->socketThread, INFINITE); + if (tsdPtr->socketThread) { + CloseHandle(tsdPtr->socketThread); + tsdPtr->socketThread = NULL; + } + } } if (tsdPtr->readyEvent != NULL) { CloseHandle(tsdPtr->readyEvent); @@ -2263,6 +2265,11 @@ SocketThread( SetEvent(tsdPtr->readyEvent); + tsdPtr->hwnd = NULL; + CloseHandle(tsdPtr->socketThread); + tsdPtr->socketThread = NULL; + + TclWinThreadExit(msg.wParam); return msg.wParam; } diff --git a/win/tclWinTime.c b/win/tclWinTime.c index 46e2cd2..fc29982 100644 --- a/win/tclWinTime.c +++ b/win/tclWinTime.c @@ -10,7 +10,7 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ -#include "tclInt.h" +#include "tclWinInt.h" #define SECSPERDAY (60L * 60L * 24L) #define SECSPERYEAR (SECSPERDAY * 365L) @@ -394,13 +394,12 @@ NativeGetTime( */ if (timeInfo.perfCounterAvailable) { - DWORD id; InitializeCriticalSection(&timeInfo.cs); timeInfo.readyEvent = CreateEvent(NULL, FALSE, FALSE, NULL); timeInfo.exitEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - timeInfo.calibrationThread = CreateThread(NULL, 256, - CalibrationThread, (LPVOID) NULL, 0, &id); + timeInfo.calibrationThread = TclWinThreadCreate(NULL, + CalibrationThread, (LPVOID) NULL, 256); SetThreadPriority(timeInfo.calibrationThread, THREAD_PRIORITY_HIGHEST); @@ -912,6 +911,7 @@ CalibrationThread( } /* lint */ + TclWinThreadExit(0); return (DWORD) 0; } |