From 058d31d7b5d68a7bc7c5b3433096e68ac4cf1331 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 10 Oct 2009 11:00:35 +0000 Subject: [PATCH] From Mathias Froehlich, "Tha attached change adapt previous attemps to get our application using osg through microsofts application verifier. The current change should work a little better ... The change is based on rev 10605." --- src/OpenThreads/win32/Win32Thread.cpp | 5 ++++- src/OpenThreads/win32/Win32ThreadPrivateData.h | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/OpenThreads/win32/Win32Thread.cpp b/src/OpenThreads/win32/Win32Thread.cpp index 1780559dc..9a82efa00 100644 --- a/src/OpenThreads/win32/Win32Thread.cpp +++ b/src/OpenThreads/win32/Win32Thread.cpp @@ -205,7 +205,10 @@ namespace OpenThreads { Thread* Thread::CurrentThread() { - return (Thread* )TlsGetValue(Win32ThreadPrivateData::TLS.getId()); + DWORD ID = Win32ThreadPrivateData::TLS.getId(); + if (ID == TLS_OUT_OF_INDEXES) + return 0; + return (Thread* )TlsGetValue(ID); } //---------------------------------------------------------------------------- diff --git a/src/OpenThreads/win32/Win32ThreadPrivateData.h b/src/OpenThreads/win32/Win32ThreadPrivateData.h index 451c1af42..554edb811 100644 --- a/src/OpenThreads/win32/Win32ThreadPrivateData.h +++ b/src/OpenThreads/win32/Win32ThreadPrivateData.h @@ -71,18 +71,21 @@ public: struct TlsHolder{ // thread local storage slot DWORD getId() { - static bool initialized = false; if (!initialized) { ID = TlsAlloc(); initialized = true; } return ID; } + TlsHolder() : ID(TLS_OUT_OF_INDEXES), initialized(false) {} ~TlsHolder(){ - TlsFree(ID); + if (initialized) + TlsFree(ID); + ID = TLS_OUT_OF_INDEXES; } private: DWORD ID; + bool initialized; }; static TlsHolder TLS;