Browse Source

Remove WinRun hack from hsThread

Adam Johnson 13 years ago committed by Darryl Pogue
parent
commit
a44b48356e
  1. 4
      Sources/Plasma/CoreLib/hsThread.h
  2. 36
      Sources/Plasma/CoreLib/hsThread_Win.cpp

4
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
};
//////////////////////////////////////////////////////////////////////////////

36
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)

Loading…
Cancel
Save