mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(thread): implement SCreateThread for Linux
This commit is contained in:
parent
db87a5d782
commit
9475df632d
3 changed files with 92 additions and 1 deletions
|
|
@ -30,7 +30,17 @@ class S_Thread {
|
||||||
static SThreadTrack s_threads[1024];
|
static SThreadTrack s_threads[1024];
|
||||||
|
|
||||||
// Static functions
|
// Static functions
|
||||||
|
#if defined(WHOA_SYSTEM_WIN)
|
||||||
static uint32_t s_SLaunchThread(void* threadParam);
|
static uint32_t s_SLaunchThread(void* threadParam);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WHOA_SYSTEM_MAC)
|
||||||
|
static uint32_t s_SLaunchThread(void* threadParam);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WHOA_SYSTEM_LINUX)
|
||||||
|
static void* s_SLaunchThread(void* threadParam);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
6
storm/thread/linux/S_Thread.cpp
Normal file
6
storm/thread/linux/S_Thread.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "storm/thread/S_Thread.hpp"
|
||||||
|
#include "storm/Memory.hpp"
|
||||||
|
|
||||||
|
void* S_Thread::s_SLaunchThread(void* threadParam) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,81 @@
|
||||||
#include "storm/Thread.hpp"
|
#include "storm/Thread.hpp"
|
||||||
|
#include "storm/Memory.hpp"
|
||||||
|
#include "storm/String.hpp"
|
||||||
|
#include "storm/thread/S_Thread.hpp"
|
||||||
|
#include <cstdio>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
void* SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3, SThread* syncObject, const char* threadName) {
|
void* SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3, SThread* syncObject, const char* threadName) {
|
||||||
|
if (!threadName) {
|
||||||
|
threadName = "";
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
return reinterpret_cast<void*>(1);
|
// S_Thread::s_threadCrit.Enter();
|
||||||
|
|
||||||
|
if (!S_Thread::s_numthreads) {
|
||||||
|
uint32_t threadId = S_Thread::s_threadID++;
|
||||||
|
|
||||||
|
auto& mainThread = S_Thread::s_threads[0];
|
||||||
|
mainThread.suspended = 0;
|
||||||
|
mainThread.live = 1;
|
||||||
|
mainThread.threadId = threadId;
|
||||||
|
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;
|
||||||
|
SStrCopy(cdThread.name, "CdThreadProc", sizeof(cdThread.name));
|
||||||
|
|
||||||
|
S_Thread::s_numthreads++;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t threadId = S_Thread::s_threadID++;
|
||||||
|
|
||||||
|
void* m = SMemAlloc(sizeof(SThreadParmBlock), __FILE__, __LINE__, 0x8);
|
||||||
|
auto params = new (m) SThreadParmBlock();
|
||||||
|
params->threadProc = threadProc;
|
||||||
|
params->threadParam = threadParam;
|
||||||
|
params->threadID = threadId;
|
||||||
|
params->syncObject = syncObject;
|
||||||
|
|
||||||
|
if (syncObject) {
|
||||||
|
syncObject->m_value1 = 0;
|
||||||
|
pthread_cond_init(&syncObject->m_cond, nullptr);
|
||||||
|
pthread_mutex_init(&syncObject->m_mutex, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_attr_t pthreadAttr;
|
||||||
|
pthread_attr_init(&pthreadAttr);
|
||||||
|
pthread_attr_setdetachstate(&pthreadAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
|
pthread_t pthread;
|
||||||
|
if (pthread_create(&pthread, &pthreadAttr, S_Thread::s_SLaunchThread, params) != 0) {
|
||||||
|
perror("pthread_create");
|
||||||
|
syncObject->m_value1 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& thread = S_Thread::s_threads[S_Thread::s_numthreads];
|
||||||
|
thread.suspended = 0;
|
||||||
|
thread.live = 1;
|
||||||
|
thread.threadId = threadId;
|
||||||
|
|
||||||
|
if (threadName) {
|
||||||
|
SStrCopy(thread.name, threadName, sizeof(thread.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
S_Thread::s_numthreads++;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// S_Thread::s_threadCrit.Leave();
|
||||||
|
|
||||||
|
return reinterpret_cast<void*>(pthread);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue