diff --git a/storm/Thread.cpp b/storm/Thread.cpp new file mode 100644 index 0000000..8563eac --- /dev/null +++ b/storm/Thread.cpp @@ -0,0 +1,19 @@ +#include "storm/Thread.hpp" + +#if defined(WHOA_SYSTEM_WIN) +#include +#endif + +#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) +#include +#endif + +uintptr_t SGetCurrentThreadId() { +#if defined(WHOA_SYSTEM_WIN) + return GetCurrentThreadId(); +#endif + +#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) + return reinterpret_cast(pthread_self()); +#endif +} diff --git a/storm/Thread.hpp b/storm/Thread.hpp index 0a0463e..4f22614 100644 --- a/storm/Thread.hpp +++ b/storm/Thread.hpp @@ -11,4 +11,6 @@ int32_t SCreateThread(uint32_t (*threadProc)(void*), void* threadParam, void* a3, SThread* syncObject, const char* threadName); +uintptr_t SGetCurrentThreadId(); + #endif diff --git a/test/Thread.cpp b/test/Thread.cpp new file mode 100644 index 0000000..5e2fa04 --- /dev/null +++ b/test/Thread.cpp @@ -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); + } +}