From 9dbda7a1ea9d0ac91e02bf4e605618203faf83bc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 11 Nov 2015 15:06:35 +0000 Subject: thread library: - _beginthread replaced with CreateThread(); - functions forkthread & forkthreadex removed; - macroses mir_forkthread, mir_forkthreadex & mir_forkthreadowner became real functions; git-svn-id: http://svn.miranda-ng.org/main/trunk@15710 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/src/mir_core.def | 5 ++-- src/mir_core/src/mir_core64.def | 5 ++-- src/mir_core/src/openurl.cpp | 4 +-- src/mir_core/src/threads.cpp | 57 +++++++++++++++++++++++++++++------------ 4 files changed, 48 insertions(+), 23 deletions(-) (limited to 'src/mir_core') diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 83c787d57f..fb89dde82b 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -73,8 +73,8 @@ Utf8DecodeW @72 Utf8Encode @73 Utf8EncodeCP @74 Utf8EncodeW @75 -forkthread @76 -forkthreadex @77 +mir_forkthread @76 +mir_forkthreadex @77 ltrim @78 ltrimp @79 mir_a2u @80 @@ -987,3 +987,4 @@ mir_sha256_final @1144 mir_sha256_hash @1145 mir_sha256_init @1146 mir_sha256_write @1147 +mir_forkthreadowner @1148 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 86b36cd57a..f7cb356fdb 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -73,8 +73,8 @@ Utf8DecodeW @72 Utf8Encode @73 Utf8EncodeCP @74 Utf8EncodeW @75 -forkthread @76 -forkthreadex @77 +mir_forkthread @76 +mir_forkthreadex @77 ltrim @78 ltrimp @79 mir_a2u @80 @@ -987,3 +987,4 @@ mir_sha256_final @1144 mir_sha256_hash @1145 mir_sha256_init @1146 mir_sha256_write @1147 +mir_forkthreadowner @1148 diff --git a/src/mir_core/src/openurl.cpp b/src/mir_core/src/openurl.cpp index 00b2813322..3da41fb107 100644 --- a/src/mir_core/src/openurl.cpp +++ b/src/mir_core/src/openurl.cpp @@ -68,11 +68,11 @@ static void OpenURLThread(void *arg) MIR_CORE_DLL(void) Utils_OpenUrl(const char *pszUrl, bool bOpenInNewWindow) { if (pszUrl) - forkthread(OpenURLThread, 0, new TOpenUrlInfo(mir_a2t(pszUrl), bOpenInNewWindow)); + mir_forkthread(OpenURLThread, new TOpenUrlInfo(mir_a2t(pszUrl), bOpenInNewWindow)); } MIR_CORE_DLL(void) Utils_OpenUrlW(const wchar_t *pszUrl, bool bOpenInNewWindow) { if (pszUrl) - forkthread(OpenURLThread, 0, new TOpenUrlInfo(mir_wstrdup(pszUrl), bOpenInNewWindow)); + mir_forkthread(OpenURLThread, new TOpenUrlInfo(mir_wstrdup(pszUrl), bOpenInNewWindow)); } diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp index dddcfe2d83..8f73d5bb4d 100644 --- a/src/mir_core/src/threads.cpp +++ b/src/mir_core/src/threads.cpp @@ -108,7 +108,7 @@ struct FORK_ARG ///////////////////////////////////////////////////////////////////////////////////////// // forkthread - starts a new thread -void __cdecl forkthread_r(void *arg) +DWORD WINAPI forkthread_r(void *arg) { FORK_ARG *fa = (FORK_ARG*)arg; pThreadFunc callercode = fa->threadcode; @@ -120,26 +120,31 @@ void __cdecl forkthread_r(void *arg) SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); Thread_Pop(); + return 0; } -MIR_CORE_DLL(UINT_PTR) forkthread(void(__cdecl *threadcode)(void*), unsigned long stacksize, void *arg) +MIR_CORE_DLL(HANDLE) mir_forkthread(void(__cdecl *threadcode)(void*), void *arg) { FORK_ARG fa; fa.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); fa.threadcode = threadcode; fa.arg = arg; - UINT_PTR rc = _beginthread(forkthread_r, stacksize, &fa); - if ((UINT_PTR)-1L != rc) + + DWORD threadID; + HANDLE hThread = CreateThread(NULL, 0, forkthread_r, &fa, 0, &threadID); + if (hThread != NULL) { WaitForSingleObject(fa.hEvent, INFINITE); + CloseHandle(hThread); + } CloseHandle(fa.hEvent); - return rc; + return hThread; } ///////////////////////////////////////////////////////////////////////////////////////// // forkthreadex - starts a new thread with the extended info and returns the thread id -unsigned __stdcall forkthreadex_r(void * arg) +DWORD WINAPI forkthreadex_r(void * arg) { struct FORK_ARG *fa = (struct FORK_ARG *)arg; pThreadFuncEx threadcode = fa->threadcodeex; @@ -160,25 +165,43 @@ unsigned __stdcall forkthreadex_r(void * arg) return rc; } -MIR_CORE_DLL(UINT_PTR) forkthreadex( - void *sec, - unsigned stacksize, - unsigned(__stdcall *threadcode)(void*), - void *owner, - void *arg, - unsigned *thraddr) +MIR_CORE_DLL(HANDLE) mir_forkthreadex(pThreadFuncEx aFunc, void* arg, unsigned *pThreadID) +{ + struct FORK_ARG fa = { 0 }; + fa.threadcodeex = aFunc; + fa.arg = arg; + fa.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + DWORD threadID = 0; + HANDLE hThread = CreateThread(NULL, 0, forkthreadex_r, &fa, 0, &threadID); + if (hThread != NULL) + WaitForSingleObject(fa.hEvent, INFINITE); + + if (pThreadID != NULL) + *pThreadID = threadID; + + CloseHandle(fa.hEvent); + return hThread; +} + +MIR_CORE_DLL(HANDLE) mir_forkthreadowner(pThreadFuncOwner aFunc, void *owner, void *arg, unsigned *pThreadID) { struct FORK_ARG fa = { 0 }; - fa.threadcodeex = threadcode; + fa.threadcodeex = (pThreadFuncEx)aFunc; fa.arg = arg; fa.owner = owner; fa.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - UINT_PTR rc = _beginthreadex(sec, stacksize, forkthreadex_r, (void *)&fa, 0, thraddr); - if (rc) + + DWORD threadID = 0; + HANDLE hThread = CreateThread(NULL, 0, forkthreadex_r, &fa, 0, &threadID); + if (hThread != NULL) WaitForSingleObject(fa.hEvent, INFINITE); + if (pThreadID != NULL) + *pThreadID = threadID; + CloseHandle(fa.hEvent); - return rc; + return hThread; } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3