diff --git a/src/OpenThreads/win32/Win32Thread.cpp b/src/OpenThreads/win32/Win32Thread.cpp index afa8dd70a..7e17f8362 100644 --- a/src/OpenThreads/win32/Win32Thread.cpp +++ b/src/OpenThreads/win32/Win32Thread.cpp @@ -98,7 +98,7 @@ namespace OpenThreads { if (thread->_prvData==0) return 0; - TlsSetValue(Win32ThreadPrivateData::TLS.ID ,data); + TlsSetValue(Win32ThreadPrivateData::TLS.getId(), data); //--------------------------------------------------------------------- // Set the proper scheduling priorities // @@ -127,6 +127,7 @@ namespace OpenThreads { // abnormal termination but must be caught in win32 anyway } + TlsSetValue(Win32ThreadPrivateData::TLS.getId(), 0); pd->isRunning = false; return 0; @@ -207,7 +208,7 @@ namespace OpenThreads { Thread* Thread::CurrentThread() { - return (Thread* )TlsGetValue(Win32ThreadPrivateData::TLS.ID); + return (Thread* )TlsGetValue(Win32ThreadPrivateData::TLS.getId()); }; //---------------------------------------------------------------------------- diff --git a/src/OpenThreads/win32/Win32ThreadPrivateData.h b/src/OpenThreads/win32/Win32ThreadPrivateData.h index e26b65b19..451c1af42 100644 --- a/src/OpenThreads/win32/Win32ThreadPrivateData.h +++ b/src/OpenThreads/win32/Win32ThreadPrivateData.h @@ -69,12 +69,20 @@ public: HandleHolder cancelEvent; struct TlsHolder{ // thread local storage slot - DWORD ID; - TlsHolder(): ID(TlsAlloc()){ + DWORD getId() + { + static bool initialized = false; + if (!initialized) { + ID = TlsAlloc(); + initialized = true; + } + return ID; } ~TlsHolder(){ TlsFree(ID); } + private: + DWORD ID; }; static TlsHolder TLS;