summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-11-11 15:06:35 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-11-11 15:06:35 +0000
commit9dbda7a1ea9d0ac91e02bf4e605618203faf83bc (patch)
treea9bd5e9b1d65664ac00635d8fd2ecd1217df5c85 /src
parentd6990ccddb9d6f432fd0392e241d48f95102cf13 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/core/stdemail/src/email.cpp2
-rw-r--r--src/core/stdfile/src/fileexistsdlg.cpp2
-rw-r--r--src/core/stdfile/src/filesenddlg.cpp2
-rw-r--r--src/core/stdfile/src/filexferdlg.cpp4
-rw-r--r--src/core/stduihist/src/history.cpp2
-rw-r--r--src/mir_app/src/miranda.cpp2
-rw-r--r--src/mir_app/src/netlibopenconn.cpp2
-rw-r--r--src/mir_app/src/searchresults.cpp4
-rw-r--r--src/mir_core/src/mir_core.def5
-rw-r--r--src/mir_core/src/mir_core64.def5
-rw-r--r--src/mir_core/src/openurl.cpp4
-rw-r--r--src/mir_core/src/threads.cpp57
12 files changed, 58 insertions, 33 deletions
diff --git a/src/core/stdemail/src/email.cpp b/src/core/stdemail/src/email.cpp
index f07e3d8060..d0a0f17f48 100644
--- a/src/core/stdemail/src/email.cpp
+++ b/src/core/stdemail/src/email.cpp
@@ -46,7 +46,7 @@ static INT_PTR SendEMailCommand(WPARAM hContact, LPARAM lParam)
mir_strcpy(szUrl, "mailto:");
mir_strcat(szUrl, dbv.pszVal);
mir_free(dbv.pszVal);
- forkthread(SendEmailThread, 0, szUrl);
+ mir_forkthread(SendEmailThread, szUrl);
return 0;
}
diff --git a/src/core/stdfile/src/fileexistsdlg.cpp b/src/core/stdfile/src/fileexistsdlg.cpp
index ef765b56bf..ba340963ff 100644
--- a/src/core/stdfile/src/fileexistsdlg.cpp
+++ b/src/core/stdfile/src/fileexistsdlg.cpp
@@ -233,7 +233,7 @@ INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
lisi->hwndDlg = hwndDlg;
lisi->szFilename = mir_tstrdup(fts->tszCurrentFile);
//can be a little slow, so why not?
- forkthread(LoadIconsAndTypesThread, 0, lisi);
+ mir_forkthread(LoadIconsAndTypesThread, lisi);
SetFocus(hwndFocus);
SetWindowLongPtr(hwndFocus, GWL_STYLE, GetWindowLongPtr(hwndFocus, GWL_STYLE) | BS_DEFPUSHBUTTON);
}
diff --git a/src/core/stdfile/src/filesenddlg.cpp b/src/core/stdfile/src/filesenddlg.cpp
index 75d955897b..14bf93cf53 100644
--- a/src/core/stdfile/src/filesenddlg.cpp
+++ b/src/core/stdfile/src/filesenddlg.cpp
@@ -313,7 +313,7 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
switch (LOWORD(wParam)) {
case IDC_CHOOSE:
EnableWindow(hwndDlg, FALSE);
- forkthread(ChooseFilesThread, 0, hwndDlg);
+ mir_forkthread(ChooseFilesThread, hwndDlg);
break;
case IDOK:
diff --git a/src/core/stdfile/src/filexferdlg.cpp b/src/core/stdfile/src/filexferdlg.cpp
index 804318123b..9dc6c22447 100644
--- a/src/core/stdfile/src/filexferdlg.cpp
+++ b/src/core/stdfile/src/filexferdlg.cpp
@@ -530,7 +530,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
vstsi->hwndReply = hwndDlg;
vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]);
vstsi->returnCode = dat->transferStatus.currentFileNumber;
- forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi);
+ mir_forkthread((void(*)(void*))RunVirusScannerThread, vstsi);
}
}
break;
@@ -673,7 +673,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
}
SetFtStatus(hwndDlg, LPGENT("Scanning for viruses..."), FTS_TEXT);
if (vstsi)
- forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi);
+ mir_forkthread((void(*)(void*))RunVirusScannerThread, vstsi);
}
else dat->fs = NULL; /* protocol will free structure */
diff --git a/src/core/stduihist/src/history.cpp b/src/core/stduihist/src/history.cpp
index f5ef654864..7c8fd84bc1 100644
--- a/src/core/stduihist/src/history.cpp
+++ b/src/core/stduihist/src/history.cpp
@@ -221,7 +221,7 @@ static INT_PTR CALLBACK DlgProcHistory(HWND hwndDlg, UINT msg, WPARAM wParam, LP
EnableWindow(GetDlgItem(hwndDlg, IDC_LIST), FALSE);
hInfo->hContact = hContact;
hInfo->hwnd = hwndDlg;
- forkthread(FillHistoryThread, 0, hInfo);
+ mir_forkthread(FillHistoryThread, hInfo);
}
return TRUE;
diff --git a/src/mir_app/src/miranda.cpp b/src/mir_app/src/miranda.cpp
index 6c908228ba..43f32a6111 100644
--- a/src/mir_app/src/miranda.cpp
+++ b/src/mir_app/src/miranda.cpp
@@ -254,7 +254,7 @@ int WINAPI mir_main(LPTSTR cmdLine)
// ensure that the kernel hooks the SystemShutdownProc() after all plugins
HookEvent(ME_SYSTEM_SHUTDOWN, SystemShutdownProc);
- forkthread(compactHeapsThread, 0, NULL);
+ mir_forkthread(compactHeapsThread);
CreateServiceFunction(MS_SYSTEM_SETIDLECALLBACK, SystemSetIdleCallback);
CreateServiceFunction(MS_SYSTEM_GETIDLE, SystemGetIdle);
dwEventTime = GetTickCount();
diff --git a/src/mir_app/src/netlibopenconn.cpp b/src/mir_app/src/netlibopenconn.cpp
index 5ffbce24ed..5219375678 100644
--- a/src/mir_app/src/netlibopenconn.cpp
+++ b/src/mir_app/src/netlibopenconn.cpp
@@ -865,7 +865,7 @@ INT_PTR NetlibOpenConnection(WPARAM wParam, LPARAM lParam)
mir_cslock lck(csNetlibUser);
if (iUPnPCleanup == 0) {
iUPnPCleanup = 1;
- forkthread(NetlibUPnPCleanup, 0, NULL);
+ mir_forkthread(NetlibUPnPCleanup);
}
}
diff --git a/src/mir_app/src/searchresults.cpp b/src/mir_app/src/searchresults.cpp
index b75ca7746d..514dd03f6a 100644
--- a/src/mir_app/src/searchresults.cpp
+++ b/src/mir_app/src/searchresults.cpp
@@ -210,7 +210,7 @@ int BeginSearch(HWND, struct FindAddDlgData *dat, const char *szProto, const cha
if (failures) {
//infuriatingly vague error message. fixme.
if (dat->searchCount == 0) {
- forkthread(BeginSearchFailed, 0, NULL);
+ mir_forkthread(BeginSearchFailed);
mir_free(dat->search);
dat->search = NULL;
return 1;
@@ -225,7 +225,7 @@ int BeginSearch(HWND, struct FindAddDlgData *dat, const char *szProto, const cha
if (dat->search[0].hProcess == NULL) {
//infuriatingly vague error message. fixme.
PROTOACCOUNT *pa = Proto_GetAccount(szProto);
- forkthread(BeginSearchFailed, 0, mir_tstrdup(pa->tszAccountName));
+ mir_forkthread(BeginSearchFailed, mir_tstrdup(pa->tszAccountName));
mir_free(dat->search);
dat->search = NULL;
dat->searchCount = 0;
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;
}
/////////////////////////////////////////////////////////////////////////////////////////