From 8a90f867ae1f600e1c82427749bbdaaac107b608 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 17 Dec 2021 15:43:58 -0600 Subject: [PATCH] feat(thread): add SGetCurrentThreadId --- storm/Thread.cpp | 19 +++++++++++++++++++ storm/Thread.hpp | 2 ++ test/Thread.cpp | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 storm/Thread.cpp create mode 100644 test/Thread.cpp 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); + } +}