From 11bae63fe16ec4747f7dee28b9f0152531623cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 10 Sep 2015 11:00:23 -0700 Subject: [PATCH] Fixed XP build. --- include/bx/thread.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/include/bx/thread.h b/include/bx/thread.h index d6b2602..a78146c 100644 --- a/include/bx/thread.h +++ b/include/bx/thread.h @@ -31,8 +31,9 @@ namespace bx public: Thread() -#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT : m_handle(INVALID_HANDLE_VALUE) + , m_threadId(UINT32_MAX) #elif BX_PLATFORM_POSIX : m_handle(0) #endif // BX_PLATFORM_ @@ -61,7 +62,7 @@ namespace bx m_stackSize = _stackSize; m_running = true; -#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 m_handle = CreateThread(NULL , m_stackSize , threadFunc @@ -101,17 +102,18 @@ namespace bx BX_CHECK(0 == result, "pthread_attr_setschedparam failed! %d", result); #endif // BX_PLATFORM_ + m_sem.wait(); + if (NULL != _name) { setThreadName(_name); } - m_sem.wait(); } void shutdown() { BX_CHECK(m_running, "Not running!"); -#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 WaitForSingleObject(m_handle, INFINITE); GetExitCodeThread(m_handle, (DWORD*)&m_exitCode); CloseHandle(m_handle); @@ -162,7 +164,7 @@ namespace bx ThreadName tn; tn.type = 0x1000; tn.name = _name; - tn.id = GetThreadId(m_handle); + tn.id = m_threadId; tn.flags = 0; __try @@ -184,11 +186,15 @@ namespace bx private: int32_t entry() { +#if BX_PLATFORM_WINDOWS + m_threadId = ::GetCurrentThreadId(); +#endif // BX_PLATFORM_WINDOWS + m_sem.post(); return m_fn(m_userData); } -#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT static DWORD WINAPI threadFunc(LPVOID _arg) { Thread* thread = (Thread*)_arg; @@ -209,18 +215,19 @@ namespace bx } #endif // BX_PLATFORM_ -#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT HANDLE m_handle; + DWORD m_threadId; #elif BX_PLATFORM_POSIX pthread_t m_handle; #endif // BX_PLATFORM_ - ThreadFn m_fn; - void* m_userData; + ThreadFn m_fn; + void* m_userData; Semaphore m_sem; - uint32_t m_stackSize; - int32_t m_exitCode; - bool m_running; + uint32_t m_stackSize; + int32_t m_exitCode; + bool m_running; }; #if BX_PLATFORM_WINDOWS