mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
feat(thread): implement SThread::Create for windows
This commit is contained in:
parent
4dbfb0b3be
commit
db87a5d782
7 changed files with 41 additions and 6 deletions
|
|
@ -27,6 +27,14 @@ if(WHOA_SYSTEM_MAC)
|
||||||
list(APPEND STORM_SOURCES ${STORM_MAC_SOURCES})
|
list(APPEND STORM_SOURCES ${STORM_MAC_SOURCES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(WHOA_SYSTEM_LINUX)
|
||||||
|
file(GLOB STORM_LINUX_SOURCES
|
||||||
|
"linux/*.cpp"
|
||||||
|
"thread/linux/*.cpp"
|
||||||
|
)
|
||||||
|
list(APPEND STORM_SOURCES ${STORM_LINUX_SOURCES})
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(storm STATIC
|
add_library(storm STATIC
|
||||||
${STORM_SOURCES}
|
${STORM_SOURCES}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#include "storm/thread/SThread.hpp"
|
#include "storm/thread/SThread.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
int32_t 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);
|
||||||
|
|
||||||
uintptr_t SGetCurrentThreadId();
|
uintptr_t SGetCurrentThreadId();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
int32_t SThread::Create(uint32_t (*threadProc)(void*), void* param, SThread& thread, char* threadName, uint32_t a5) {
|
int32_t SThread::Create(uint32_t (*threadProc)(void*), void* param, SThread& thread, char* threadName, uint32_t a5) {
|
||||||
#if defined(WHOA_SYSTEM_WIN)
|
#if defined(WHOA_SYSTEM_WIN)
|
||||||
// TODO implement
|
uint32_t v8;
|
||||||
return 0;
|
auto handle = SCreateThread(threadProc, param, &v8, nullptr, nullptr);
|
||||||
|
thread.m_opaqueData = handle;
|
||||||
|
return handle != nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
|
||||||
|
|
@ -13,6 +15,7 @@ int32_t SThread::Create(uint32_t (*threadProc)(void*), void* param, SThread& thr
|
||||||
pthread_cond_init(&thread.m_cond, nullptr);
|
pthread_cond_init(&thread.m_cond, nullptr);
|
||||||
|
|
||||||
uint32_t v8;
|
uint32_t v8;
|
||||||
return SCreateThread(threadProc, param, &v8, &thread, nullptr) != 0;
|
auto handle = SCreateThread(threadProc, param, &v8, &thread, nullptr);
|
||||||
|
return handle != nullptr;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
storm/thread/linux/Thread.cpp
Normal file
6
storm/thread/linux/Thread.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "storm/Thread.hpp"
|
||||||
|
|
||||||
|
void* SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3, SThread* syncObject, const char* threadName) {
|
||||||
|
// TODO
|
||||||
|
return reinterpret_cast<void*>(1);
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include "storm/thread/mac/SThreadRunner.h"
|
#include "storm/thread/mac/SThreadRunner.h"
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
int32_t 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) {
|
if (!threadName) {
|
||||||
threadName = "";
|
threadName = "";
|
||||||
}
|
}
|
||||||
|
|
@ -71,5 +71,5 @@ int32_t SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3
|
||||||
// TODO
|
// TODO
|
||||||
// S_Thread::s_threadCrit.Leave();
|
// S_Thread::s_threadCrit.Leave();
|
||||||
|
|
||||||
return threadId;
|
return reinterpret_cast<void*>(threadId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
storm/thread/win/Thread.cpp
Normal file
6
storm/thread/win/Thread.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "storm/Thread.hpp"
|
||||||
|
|
||||||
|
void* SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3, SThread* syncObject, const char* threadName) {
|
||||||
|
// TODO
|
||||||
|
return reinterpret_cast<void*>(1);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
#include "storm/Thread.hpp"
|
#include "storm/Thread.hpp"
|
||||||
#include "test/Test.hpp"
|
#include "test/Test.hpp"
|
||||||
|
|
||||||
|
uint32_t threadProc(void* param) {
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
TEST_CASE("SGetCurrentThreadId", "[thread]") {
|
TEST_CASE("SGetCurrentThreadId", "[thread]") {
|
||||||
SECTION("returns thread id") {
|
SECTION("returns thread id") {
|
||||||
uintptr_t threadId = SGetCurrentThreadId();
|
uintptr_t threadId = SGetCurrentThreadId();
|
||||||
|
|
@ -24,3 +28,11 @@ TEST_CASE("SCritSect::Leave", "[thread]") {
|
||||||
SUCCEED();
|
SUCCEED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("SThread::Create", "[thread]") {
|
||||||
|
SECTION("creates new thread") {
|
||||||
|
SThread thread;
|
||||||
|
char* threadName = const_cast<char*>("TestThread");
|
||||||
|
REQUIRE(SThread::Create(threadProc, nullptr, thread, threadName, 0) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue