diff options
-rw-r--r-- | sal/osl/w32/dllentry.cxx | 4 | ||||
-rw-r--r-- | sal/osl/w32/thread.cxx | 35 | ||||
-rw-r--r-- | sal/osl/w32/thread.hxx | 2 |
3 files changed, 10 insertions, 31 deletions
diff --git a/sal/osl/w32/dllentry.cxx b/sal/osl/w32/dllentry.cxx index a36e6cda8840..81139a05852b 100644 --- a/sal/osl/w32/dllentry.cxx +++ b/sal/osl/w32/dllentry.cxx @@ -84,8 +84,6 @@ static BOOL WINAPI RawDllMain( HINSTANCE, DWORD fdwReason, LPVOID ) SetErrorMode( SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS ); #endif - g_dwTLSTextEncodingIndex = TlsAlloc(); - //We disable floating point exceptions. This is the usual state at program startup //but on Windows 98 and ME this is not always the case. _control87(_MCW_EM, _MCW_EM); @@ -95,8 +93,6 @@ static BOOL WINAPI RawDllMain( HINSTANCE, DWORD fdwReason, LPVOID ) case DLL_PROCESS_DETACH: WSACleanup( ); - TlsFree( g_dwTLSTextEncodingIndex ); - /* On a product build memory management finalization might diff --git a/sal/osl/w32/thread.cxx b/sal/osl/w32/thread.cxx index f11c17668371..c10950e9151f 100644 --- a/sal/osl/w32/thread.cxx +++ b/sal/osl/w32/thread.cxx @@ -520,36 +520,21 @@ sal_Bool SAL_CALL osl_setThreadKeyData(oslThreadKey Key, void *pData) return false; } -DWORD g_dwTLSTextEncodingIndex = DWORD(-1); - -rtl_TextEncoding SAL_CALL osl_getThreadTextEncoding(void) +namespace { - DWORD_PTR dwEncoding; - rtl_TextEncoding _encoding; - bool gotACP; - - if ( DWORD(-1) == g_dwTLSTextEncodingIndex ) - g_dwTLSTextEncodingIndex = TlsAlloc(); - - dwEncoding = reinterpret_cast<DWORD_PTR>(TlsGetValue( g_dwTLSTextEncodingIndex )); - _encoding = LOWORD(dwEncoding); - gotACP = HIWORD(dwEncoding); - - if ( !gotACP ) - { - _encoding = rtl_getTextEncodingFromWindowsCodePage( GetACP() ); - TlsSetValue( g_dwTLSTextEncodingIndex, reinterpret_cast<LPVOID>(static_cast<DWORD_PTR>(MAKELONG( _encoding, TRUE ))) ); - } - - return _encoding; +rtl_TextEncoding& getThreadTextEncodingImpl() +{ + static thread_local rtl_TextEncoding s_enc = rtl_getTextEncodingFromWindowsCodePage(GetACP()); + return s_enc; +} } +rtl_TextEncoding SAL_CALL osl_getThreadTextEncoding(void) { return getThreadTextEncodingImpl(); } + rtl_TextEncoding SAL_CALL osl_setThreadTextEncoding( rtl_TextEncoding Encoding ) { - rtl_TextEncoding oldEncoding = osl_getThreadTextEncoding(); - - TlsSetValue( g_dwTLSTextEncodingIndex, reinterpret_cast<LPVOID>(static_cast<DWORD_PTR>(MAKELONG( Encoding, TRUE))) ); - + rtl_TextEncoding oldEncoding = getThreadTextEncodingImpl(); + getThreadTextEncodingImpl() = Encoding; return oldEncoding; } diff --git a/sal/osl/w32/thread.hxx b/sal/osl/w32/thread.hxx index 03491a8341c1..8740fb72cc56 100644 --- a/sal/osl/w32/thread.hxx +++ b/sal/osl/w32/thread.hxx @@ -16,8 +16,6 @@ void osl_callThreadKeyCallbackOnThreadDetach(void); -extern DWORD g_dwTLSTextEncodingIndex; - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |