Skip to content

Commit 2230d42

Browse files
committed
Thread update
1 parent 32e997c commit 2230d42

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

Diff for: Detours.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -4857,7 +4857,6 @@ namespace Detours {
48574857

48584858
namespace Parallel {
48594859

4860-
/*
48614860
// ----------------------------------------------------------------
48624861
// Thread Data
48634862
// ----------------------------------------------------------------
@@ -4873,19 +4872,21 @@ namespace Detours {
48734872
DWORD WINAPI ThreadRoutine(PVOID lpThreadParameter) {
48744873
auto pTD = reinterpret_cast<PTHREAD_DATA>(lpThreadParameter);
48754874
if (!pTD) {
4876-
return EXIT_SUCCESS;
4875+
return EXIT_FAILURE;
48774876
}
48784877

48794878
auto pThread = static_cast<Thread*>(pTD->m_pParameter);
48804879
if (!pThread) {
4881-
return EXIT_SUCCESS;
4880+
delete pTD;
4881+
return EXIT_FAILURE;
48824882
}
48834883

48844884
auto pCallback = pThread->GetCallBack();
48854885
if (pCallback) {
48864886
pCallback(pThread->GetData());
48874887
}
48884888

4889+
delete pTD;
48894890
return EXIT_SUCCESS;
48904891
}
48914892

@@ -4940,16 +4941,16 @@ namespace Detours {
49404941
return false;
49414942
}
49424943

4943-
auto pTD = std::make_unique<THREAD_DATA>();
4944+
auto pTD = new THREAD_DATA;
49444945
if (!pTD) {
49454946
return false;
49464947
}
49474948

4948-
memset(pTD.get(), 0, sizeof(THREAD_DATA));
4949+
memset(pTD, 0, sizeof(THREAD_DATA));
49494950

49504951
pTD->m_pParameter = this;
49514952

4952-
m_hThread = CreateThread(nullptr, NULL, ThreadRoutine, pTD.get(), NULL, nullptr);
4953+
m_hThread = CreateThread(nullptr, NULL, ThreadRoutine, pTD, NULL, nullptr);
49534954
if (!m_hThread || (m_hThread == INVALID_HANDLE_VALUE)) {
49544955
return false;
49554956
}
@@ -4966,6 +4967,20 @@ namespace Detours {
49664967
return false;
49674968
}
49684969

4970+
DWORD unExitCode = EXIT_SUCCESS;
4971+
if (!GetExitCodeThread(m_hThread, &unExitCode)) {
4972+
CloseHandle(m_hThread);
4973+
m_hThread = nullptr;
4974+
return false;
4975+
}
4976+
4977+
CloseHandle(m_hThread);
4978+
m_hThread = nullptr;
4979+
4980+
if (unExitCode != EXIT_SUCCESS) {
4981+
return false;
4982+
}
4983+
49694984
return true;
49704985
}
49714986

@@ -5000,7 +5015,6 @@ namespace Detours {
50005015
void* Thread::GetData() const {
50015016
return m_pData;
50025017
}
5003-
*/
50045018

50055019
// ----------------------------------------------------------------
50065020
// Fiber Data

Diff for: Detours.h

-2
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,6 @@ namespace Detours {
22692269

22702270
namespace Parallel {
22712271

2272-
/*
22732272
// ----------------------------------------------------------------
22742273
// Thread CallBack
22752274
// ----------------------------------------------------------------
@@ -2306,7 +2305,6 @@ namespace Detours {
23062305
void* m_pData;
23072306
HANDLE m_hThread;
23082307
};
2309-
*/
23102308

23112309
// ----------------------------------------------------------------
23122310
// Fiber CallBack

Diff for: main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1925,11 +1925,11 @@ int _tmain(int nArguments, PTCHAR* pArguments) {
19251925

19261926
_tprintf_s(_T("Parallel Example\n\n"));
19271927

1928-
//Detours::Parallel::Thread DetoursThread(OnThread);
1928+
Detours::Parallel::Thread DetoursThread(OnThread);
19291929
Detours::Parallel::Fiber DetoursFiber(OnFiber);
19301930

1931-
//_tprintf_s(_T("DetoursThread.Start() = %d\n"), DetoursThread.Start());
1932-
//_tprintf_s(_T("DetoursThread.Join() = %d\n"), DetoursThread.Join());
1931+
_tprintf_s(_T("DetoursThread.Start() = %d\n"), DetoursThread.Start());
1932+
_tprintf_s(_T("DetoursThread.Join() = %d\n"), DetoursThread.Join());
19331933

19341934
_tprintf_s(_T("DetoursFiber.Switch() = %d\n"), DetoursFiber.Switch());
19351935

0 commit comments

Comments
 (0)