mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(thread): implement SCreateThread for windows
This commit is contained in:
parent
b5cef8cbee
commit
968bb5d3b7
3 changed files with 80 additions and 2 deletions
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
#include "storm/thread/SThread.hpp"
|
||||
#include <cstdint>
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
typedef SThread SyncObjectData;
|
||||
|
||||
|
|
@ -10,7 +13,12 @@ struct SThreadParmBlock {
|
|||
uint32_t (*threadProc)(void*);
|
||||
void* threadParam;
|
||||
uint32_t threadID;
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
HANDLE threadH;
|
||||
#endif
|
||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||
SyncObjectData* syncObject;
|
||||
#endif
|
||||
};
|
||||
|
||||
class S_Thread {
|
||||
|
|
@ -20,6 +28,9 @@ class S_Thread {
|
|||
int32_t suspended;
|
||||
int32_t live;
|
||||
uint32_t threadId;
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
HANDLE threadH;
|
||||
#endif
|
||||
char name[16];
|
||||
};
|
||||
|
||||
|
|
@ -31,7 +42,7 @@ class S_Thread {
|
|||
|
||||
// Static functions
|
||||
#if defined(WHOA_SYSTEM_WIN)
|
||||
static uint32_t s_SLaunchThread(void* threadParam);
|
||||
static DWORD s_SLaunchThread(void* threadParam);
|
||||
#endif
|
||||
|
||||
#if defined(WHOA_SYSTEM_MAC)
|
||||
|
|
|
|||
6
storm/thread/win/S_Thread.cpp
Normal file
6
storm/thread/win/S_Thread.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "storm/thread/S_Thread.hpp"
|
||||
|
||||
DWORD S_Thread::s_SLaunchThread(void* threadParam) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,6 +1,67 @@
|
|||
#include "storm/Thread.hpp"
|
||||
#include "storm/Memory.hpp"
|
||||
#include "storm/String.hpp"
|
||||
#include "storm/thread/S_Thread.hpp"
|
||||
#include <new>
|
||||
#include <windows.h>
|
||||
|
||||
void* SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3, SThread* syncObject, const char* threadName) {
|
||||
// TODO
|
||||
return reinterpret_cast<void*>(1);
|
||||
if (!threadName) {
|
||||
threadName = "";
|
||||
}
|
||||
|
||||
// TODO
|
||||
// S_Thread::s_threadCrit.Enter();
|
||||
|
||||
if (!S_Thread::s_numthreads) {
|
||||
auto& mainThread = S_Thread::s_threads[0];
|
||||
mainThread.suspended = 0;
|
||||
mainThread.live = 1;
|
||||
mainThread.threadId = GetCurrentThreadId();
|
||||
mainThread.threadH = nullptr;
|
||||
SStrCopy(mainThread.name, "main", sizeof(mainThread.name));
|
||||
|
||||
S_Thread::s_numthreads++;
|
||||
|
||||
// TODO
|
||||
/*
|
||||
if (StormGetOption(8, &v32, v33)) {
|
||||
auto& cdThread = S_Thread::s_threads[S_Thread::s_numthreads];
|
||||
cdThread.suspended = 0;
|
||||
cdThread.live = 1;
|
||||
cdThread.threadId = v32.cdThreadId;
|
||||
cdThread.threadH = v32.threadH;
|
||||
SStrCopy(cdThread.name, "CdThreadProc", sizeof(cdThread.name));
|
||||
|
||||
S_Thread::s_numthreads++;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void* m = SMemAlloc(sizeof(SThreadParmBlock), __FILE__, __LINE__, 0x8);
|
||||
auto params = new (m) SThreadParmBlock();
|
||||
params->threadProc = threadProc;
|
||||
params->threadParam = threadParam;
|
||||
|
||||
DWORD threadId;
|
||||
// TODO pass dwStackSize and dwCreationFlags through to CreateThread
|
||||
HANDLE threadH = CreateThread(nullptr, 0, S_Thread::s_SLaunchThread, params, CREATE_SUSPENDED, &threadId);
|
||||
params->threadH = threadH;
|
||||
|
||||
auto& thread = S_Thread::s_threads[S_Thread::s_numthreads];
|
||||
thread.suspended = 0; // TODO set from dwCreationFlags
|
||||
thread.live = 1;
|
||||
thread.threadId = threadId;
|
||||
thread.threadH = threadH;
|
||||
|
||||
if (threadName) {
|
||||
SStrCopy(thread.name, threadName, sizeof(thread.name));
|
||||
}
|
||||
|
||||
S_Thread::s_numthreads++;
|
||||
|
||||
// TODO
|
||||
// S_Thread::s_threadCrit.Leave();
|
||||
|
||||
return threadH;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue