diff --git a/Sources/Plasma/CoreLib/hsThread.h b/Sources/Plasma/CoreLib/hsThread.h index 02f36a6a..8e162c3d 100644 --- a/Sources/Plasma/CoreLib/hsThread.h +++ b/Sources/Plasma/CoreLib/hsThread.h @@ -102,10 +102,6 @@ public: static void* Alloc(size_t size); // does not call operator::new(), may return nil static void Free(void* p); // does not call operator::delete() static void ThreadYield(); - -#if HS_BUILD_FOR_WIN32 - DWORD WinRun(); -#endif }; ////////////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/CoreLib/hsThread_Win.cpp b/Sources/Plasma/CoreLib/hsThread_Win.cpp index 53592484..2cde7e9e 100644 --- a/Sources/Plasma/CoreLib/hsThread_Win.cpp +++ b/Sources/Plasma/CoreLib/hsThread_Win.cpp @@ -46,16 +46,23 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsExceptions.h" #include "hsMemory.h" -// typedef unsigned int __stdcall (*EntryPtCB)(void*); - -static DWORD __stdcall gEntryPoint(void* param) +struct WinThreadParam { - return ((hsThread*)param)->WinRun(); -} + hsThread* fThread; + HANDLE fQuitSemaH; // private member of hsThread + + WinThreadParam(hsThread* t, HANDLE quit) + : fThread(t), fQuitSemaH(quit) + { } +}; static unsigned int __stdcall gEntryPointBT(void* param) { - return ((hsThread*)param)->WinRun(); + WinThreadParam* wtp = (WinThreadParam*)param; + unsigned int result = wtp->fThread->Run(); + ::ReleaseSemaphore(wtp->fQuitSemaH, 1, nil); // signal that we've quit + delete param; + return result; } hsThread::hsThread(uint32_t stackSize) : fStackSize(stackSize), fQuit(false), fThreadH(nil), fQuitSemaH(nil) @@ -74,12 +81,8 @@ void hsThread::Start() fQuitSemaH = ::CreateSemaphore(nil, 0, kPosInfinity32, nil); if (fQuitSemaH == nil) throw hsOSException(-1); - -#if 0 - fThreadH = ::CreateThread(nil, fStackSize, gEntryPoint, this, 0, &fThreadId); -#else - fThreadH = (HANDLE)_beginthreadex(nil, fStackSize, gEntryPointBT, this, 0, (unsigned int*)&fThreadId); -#endif + WinThreadParam* wtp = new WinThreadParam(this, fQuitSemaH); + fThreadH = (HANDLE)_beginthreadex(nil, fStackSize, gEntryPointBT, wtp, 0, (unsigned int*)&fThreadId); if (fThreadH == nil) throw hsOSException(-1); } @@ -100,15 +103,6 @@ void hsThread::Stop() } } -DWORD hsThread::WinRun() -{ - DWORD result = this->Run(); - - ::ReleaseSemaphore(fQuitSemaH, 1, nil); // signal that we've quit - - return result; -} - ///////////////////////////////////////////////////////////////////////////////////////// void* hsThread::Alloc(size_t size)