diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-08-09 14:29:54 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-08-09 20:15:43 +0200 |
commit | 8a0c43fa86bd32b4d47fd7e46d3ed414c9282ffa (patch) | |
tree | e86094b8f194d25c74157cf0df57b89a5c7d406b /sal/osl | |
parent | da54fbce1c9101925059b980a0d9fe441bf0461f (diff) |
Use _beginthreadex instead of CreateThread
The documentation for ExitThread [1] has this comment:
A thread in an executable that calls the C run-time library (CRT) should use
the _beginthreadex and _endthreadex functions for thread management rather
than CreateThread and ExitThread; this requires the use of the multithreaded
version of the CRT. If a thread created using CreateThread calls the CRT,
the CRT may terminate the process in low-memory conditions.
Since ~all our code uses CRT, be safe and use _beginthreadex.
[1] https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createthread
Change-Id: If3e566592e921b00240e08aa759d8cdbc421d44b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155513
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal/osl')
-rw-r--r-- | sal/osl/w32/dllentry.cxx | 9 | ||||
-rw-r--r-- | sal/osl/w32/thread.cxx | 8 |
2 files changed, 8 insertions, 9 deletions
diff --git a/sal/osl/w32/dllentry.cxx b/sal/osl/w32/dllentry.cxx index 81139a05852b..5389c056d5a2 100644 --- a/sal/osl/w32/dllentry.cxx +++ b/sal/osl/w32/dllentry.cxx @@ -18,6 +18,7 @@ */ #include <systools/win32/uwinapi.h> +#include <process.h> #include <tlhelp32.h> #include <rpc.h> #include <winsock.h> @@ -159,7 +160,7 @@ static DWORD GetParentProcessId() return dwParentProcessId; } -static DWORD WINAPI ParentMonitorThreadProc( LPVOID lpParam ) +static unsigned __stdcall ParentMonitorThreadProc(void* lpParam) { DWORD_PTR dwParentProcessId = reinterpret_cast<DWORD_PTR>(lpParam); @@ -196,8 +197,6 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID ) if ( dwResult && dwResult < SAL_N_ELEMENTS(szBuffer) ) { - DWORD dwThreadId = 0; - DWORD_PTR dwParentProcessId = static_cast<DWORD_PTR>(_wtol( szBuffer )); if ( dwParentProcessId && GetParentProcessId() == dwParentProcessId ) @@ -205,8 +204,8 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID ) // No error check, it works or it does not // Thread should only be started for headless mode, see desktop/win32/source/officeloader.cxx HANDLE hThread - = CreateThread(nullptr, 0, ParentMonitorThreadProc, - reinterpret_cast<LPVOID>(dwParentProcessId), 0, &dwThreadId); + = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, ParentMonitorThreadProc, + reinterpret_cast<LPVOID>(dwParentProcessId), 0, nullptr)); // Note: calling CreateThread in DllMain is discouraged // but this is only done in the headless mode and in // that case no other threads should be running at startup diff --git a/sal/osl/w32/thread.cxx b/sal/osl/w32/thread.cxx index f6b3109adfb9..3640d43b9992 100644 --- a/sal/osl/w32/thread.cxx +++ b/sal/osl/w32/thread.cxx @@ -43,7 +43,7 @@ namespace { typedef struct { HANDLE m_hThread; /* OS-handle used for all thread-functions */ - DWORD m_ThreadId; /* identifier for this thread */ + unsigned m_ThreadId; /* identifier for this thread */ sal_Int32 m_nTerminationRequested; oslWorkerFunction m_WorkerFunction; void* m_pData; @@ -54,7 +54,7 @@ typedef struct static oslThread oslCreateThread(oslWorkerFunction pWorker, void* pThreadData, sal_uInt32 nFlags); -static DWORD WINAPI oslWorkerWrapperFunction(_In_ LPVOID pData) +static unsigned __stdcall oslWorkerWrapperFunction(void* pData) { osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(pData); @@ -89,13 +89,13 @@ static oslThread oslCreateThread(oslWorkerFunction pWorker, pThreadImpl->m_pData= pThreadData; pThreadImpl->m_nTerminationRequested= 0; - pThreadImpl->m_hThread= CreateThread( + pThreadImpl->m_hThread= reinterpret_cast<HANDLE>(_beginthreadex( nullptr, /* no security */ 0, /* default stack-size */ oslWorkerWrapperFunction, /* worker-function */ pThreadImpl, /* provide worker-function with data */ nFlags, /* start thread immediately or suspended */ - &pThreadImpl->m_ThreadId); + &pThreadImpl->m_ThreadId)); if(pThreadImpl->m_hThread == nullptr) { |