sal/osl/w32/dllentry.cxx | 4 ---- sal/osl/w32/thread.cxx | 35 ++++++++++------------------------- sal/osl/w32/thread.hxx | 2 -- 3 files changed, 10 insertions(+), 31 deletions(-)
New commits: commit 396c2ad2daad6fe6a11703d0ae1593929834afe2 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Jan 30 19:56:46 2021 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Jan 31 00:50:34 2021 +0100 Use C++ thread_local instead of Tls* WinAPI Change-Id: I9fdbd6ba0e9b94f286a896053b837e58c75135d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110175 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> 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: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits