port(EterLib): Mutex/Thread/FileLoaderThread/GrpVertexBufferDynamic verbatim over Win32Crt kernel-object shims
Adds CreateSemaphore/ReleaseSemaphore/WaitForSingleObject/CloseHandle/ SetThreadPriority/_beginthreadex to Win32Crt; port.file_loader_thread covers the shims, CThread and both the un-Created (40250 live) and Created loader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e0cdcee2e6
commit
042bddf195
@@ -1,72 +1,181 @@
|
||||
// Platform skeleton for EterLib/FileLoaderThread.h (40250 EterLib/FileLoaderThread.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 40250 EterLib/FileLoaderThread.cpp, verbatim. The kernel32 calls resolve to the Win32Crt thread/semaphore/critical-section shims.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "EterLib/FileLoaderThread.h"
|
||||
#include "EterLib/ResourceManager.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
CFileLoaderThread::CFileLoaderThread()
|
||||
CFileLoaderThread::CFileLoaderThread() : m_bShutdowned(false), m_pArg(NULL), m_hThread(NULL), m_uThreadID(0)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
CFileLoaderThread::~CFileLoaderThread()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Create(void *) -> int
|
||||
int CFileLoaderThread::Create(void * arg)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<int>();
|
||||
Arg(arg);
|
||||
m_hThread = (HANDLE) _beginthreadex(NULL, 0, EntryPoint, this, 0, &m_uThreadID);
|
||||
|
||||
if (!m_hThread)
|
||||
return false;
|
||||
|
||||
SetThreadPriority(m_hThread, THREAD_PRIORITY_NORMAL);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Request(std::string &) -> void
|
||||
UINT CFileLoaderThread::Run(void * arg)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
if (!Setup())
|
||||
return 0;
|
||||
|
||||
return (Execute(arg));
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Fetch(TData **) -> bool
|
||||
/* Static */
|
||||
UINT CALLBACK CFileLoaderThread::EntryPoint(void * pThis)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
CFileLoaderThread * pThread = (CFileLoaderThread *) pThis;
|
||||
return pThread->Run(pThread->Arg());
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Shutdown() -> void
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CFileLoaderThread::Destroy()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
if (m_hSemaphore)
|
||||
{
|
||||
CloseHandle(m_hSemaphore);
|
||||
m_hSemaphore = NULL;
|
||||
}
|
||||
|
||||
stl_wipe(m_pRequestDeque);
|
||||
stl_wipe(m_pCompleteDeque);
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::EntryPoint(void *) -> UINT
|
||||
UINT CFileLoaderThread::Setup()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<UINT>();
|
||||
m_hSemaphore = CreateSemaphore(NULL, // no security attributes
|
||||
0, // initial count
|
||||
65535, // maximum count
|
||||
NULL); // unnamed semaphore
|
||||
if (!m_hSemaphore)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Run(void *) -> UINT
|
||||
void CFileLoaderThread::Shutdown()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<UINT>();
|
||||
if (!m_hSemaphore)
|
||||
return;
|
||||
|
||||
BOOL bRet;
|
||||
|
||||
m_bShutdowned = true;
|
||||
|
||||
do
|
||||
{
|
||||
bRet = ReleaseSemaphore(m_hSemaphore, 1, NULL);
|
||||
}
|
||||
while (!bRet);
|
||||
|
||||
WaitForSingleObject(m_hThread, 10000); // 쓰레드가 종료 되기를 10초 기다림
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Setup() -> UINT
|
||||
UINT CFileLoaderThread::Execute(void * /*pvArg*/)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<UINT>();
|
||||
while (!m_bShutdowned)
|
||||
{
|
||||
DWORD dwWaitResult;
|
||||
|
||||
dwWaitResult = WaitForSingleObject(m_hSemaphore, INFINITE);
|
||||
|
||||
if (m_bShutdowned)
|
||||
break;
|
||||
|
||||
switch (dwWaitResult)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
{
|
||||
Process();
|
||||
}
|
||||
break;
|
||||
|
||||
case WAIT_TIMEOUT:
|
||||
TraceError("CFileLoaderThread::Execute: Timeout occured while time-out interval is INIFITE");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Destroy();
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Execute(void *) -> UINT
|
||||
void CFileLoaderThread::Request(std::string & c_rstFileName) // called in main thread
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<UINT>();
|
||||
TData * pData = new TData;
|
||||
|
||||
pData->dwSize = 0;
|
||||
pData->pvBuf = NULL;
|
||||
pData->stFileName = c_rstFileName;
|
||||
|
||||
m_RequestMutex.Lock();
|
||||
m_pRequestDeque.push_back(pData);
|
||||
m_RequestMutex.Unlock();
|
||||
|
||||
++m_iRestSemCount;
|
||||
|
||||
if (!ReleaseSemaphore(m_hSemaphore, m_iRestSemCount, NULL))
|
||||
TraceError("CFileLoaderThread::Request: ReleaseSemaphore error");
|
||||
|
||||
--m_iRestSemCount;
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Destroy() -> void
|
||||
bool CFileLoaderThread::Fetch(TData ** ppData) // called in main thread
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
m_CompleteMutex.Lock();
|
||||
|
||||
if (m_pCompleteDeque.empty())
|
||||
{
|
||||
m_CompleteMutex.Unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
*ppData = m_pCompleteDeque.front();
|
||||
m_pCompleteDeque.pop_front();
|
||||
|
||||
m_CompleteMutex.Unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CFileLoaderThread::Process() -> void
|
||||
void CFileLoaderThread::Process() // called in loader thread
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
m_RequestMutex.Lock();
|
||||
|
||||
if (m_pRequestDeque.empty())
|
||||
{
|
||||
m_RequestMutex.Unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
TData * pData = m_pRequestDeque.front();
|
||||
m_pRequestDeque.pop_front();
|
||||
|
||||
m_RequestMutex.Unlock();
|
||||
|
||||
LPCVOID pvBuf;
|
||||
|
||||
if (CEterPackManager::Instance().Get(pData->File, pData->stFileName.c_str(), &pvBuf))
|
||||
{
|
||||
pData->dwSize = pData->File.Size();
|
||||
pData->pvBuf = new char [pData->dwSize];
|
||||
memcpy(pData->pvBuf, pvBuf, pData->dwSize);
|
||||
}
|
||||
|
||||
m_CompleteMutex.Lock();
|
||||
m_pCompleteDeque.push_back(pData);
|
||||
m_CompleteMutex.Unlock();
|
||||
|
||||
Sleep(g_iLoadingDelayTime);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
// Platform skeleton for EterLib/GrpVertexBufferDynamic.h (40250 EterLib/GrpVertexBufferDynamic.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 40250 EterLib/GrpVertexBufferDynamic.cpp, verbatim.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterLib/GrpVertexBufferDynamic.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
bool CDynamicVertexBuffer::Create(int vtxCount, int fvf)
|
||||
{
|
||||
if (m_lpd3dVB)
|
||||
{
|
||||
if (m_fvf == fvf)
|
||||
{
|
||||
if (m_vtxCount >= vtxCount)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
m_vtxCount = vtxCount;
|
||||
m_fvf = fvf;
|
||||
|
||||
return CGraphicVertexBuffer::Create(m_vtxCount, m_fvf, D3DUSAGE_DYNAMIC, D3DPOOL_SYSTEMMEM);
|
||||
}
|
||||
|
||||
CDynamicVertexBuffer::CDynamicVertexBuffer()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
m_vtxCount = 0;
|
||||
m_fvf = 0;
|
||||
}
|
||||
|
||||
CDynamicVertexBuffer::~CDynamicVertexBuffer()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CDynamicVertexBuffer::Create(int, int) -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
@@ -1,32 +1,23 @@
|
||||
// Platform skeleton for EterLib/Mutex.h (40250 EterLib/Mutex.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 40250 EterLib/Mutex.cpp, verbatim. The kernel32 calls resolve to the Win32Crt thread/semaphore/critical-section shims.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterLib/Mutex.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
Mutex::Mutex()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
InitializeCriticalSection(&lock);
|
||||
}
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
DeleteCriticalSection(&lock);
|
||||
}
|
||||
|
||||
auto Mutex::Lock() -> void
|
||||
void Mutex::Lock()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
EnterCriticalSection(&lock);
|
||||
}
|
||||
|
||||
auto Mutex::Unlock() -> void
|
||||
void Mutex::Unlock()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto Mutex::Trylock() -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
LeaveCriticalSection(&lock);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
// Platform skeleton for EterLib/Thread.h (40250 EterLib/Thread.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 40250 EterLib/Thread.cpp, verbatim. The kernel32 calls resolve to the Win32Crt thread/semaphore/critical-section shims.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterLib/Thread.h"
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
CThread::CThread()
|
||||
CThread::CThread() : m_pArg(NULL), m_hThread(NULL), m_uThreadID(0)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CThread::Create(void *) -> int
|
||||
int CThread::Create(void * arg)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<int>();
|
||||
Arg(arg);
|
||||
m_hThread = (HANDLE) _beginthreadex(NULL, 0, EntryPoint, this, 0, &m_uThreadID);
|
||||
|
||||
if (!m_hThread)
|
||||
return false;
|
||||
|
||||
SetThreadPriority(m_hThread, THREAD_PRIORITY_NORMAL);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CThread::EntryPoint(void *) -> UINT
|
||||
UINT CThread::Run(void * arg)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<UINT>();
|
||||
if (!Setup())
|
||||
return 0;
|
||||
|
||||
return (Execute(arg));
|
||||
}
|
||||
|
||||
auto CThread::Run(void *) -> UINT
|
||||
/* Static */
|
||||
UINT CALLBACK CThread::EntryPoint(void * pThis)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<UINT>();
|
||||
CThread * pThread = (CThread *) pThis;
|
||||
return pThread->Run(pThread->Arg());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user