feat(thread): add SGetCurrentThreadId

This commit is contained in:
fallenoak 2021-12-17 15:43:58 -06:00
parent 34e01acca5
commit 8a90f867ae
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
3 changed files with 30 additions and 0 deletions

19
storm/Thread.cpp Normal file
View file

@ -0,0 +1,19 @@
#include "storm/Thread.hpp"
#if defined(WHOA_SYSTEM_WIN)
#include <windows.h>
#endif
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
#include <pthread.h>
#endif
uintptr_t SGetCurrentThreadId() {
#if defined(WHOA_SYSTEM_WIN)
return GetCurrentThreadId();
#endif
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
return reinterpret_cast<uintptr_t>(pthread_self());
#endif
}

View file

@ -11,4 +11,6 @@
int32_t SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3, SThread* syncObject, const char* threadName); int32_t SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3, SThread* syncObject, const char* threadName);
uintptr_t SGetCurrentThreadId();
#endif #endif

9
test/Thread.cpp Normal file
View file

@ -0,0 +1,9 @@
#include "storm/Thread.hpp"
#include "test/Test.hpp"
TEST_CASE("SGetCurrentThreadId", "[thread]") {
SECTION("returns thread id") {
uintptr_t threadId = SGetCurrentThreadId();
CHECK(threadId > 0);
}
}