mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(thread): add SGetCurrentThreadId
This commit is contained in:
parent
34e01acca5
commit
8a90f867ae
3 changed files with 30 additions and 0 deletions
19
storm/Thread.cpp
Normal file
19
storm/Thread.cpp
Normal 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
|
||||||
|
}
|
||||||
|
|
@ -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
9
test/Thread.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue