diff options
Diffstat (limited to '3rdparty/bx/src/thread.cpp')
-rw-r--r-- | 3rdparty/bx/src/thread.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/3rdparty/bx/src/thread.cpp b/3rdparty/bx/src/thread.cpp index 70ea4a0ecbe..fe7f3491dc2 100644 --- a/3rdparty/bx/src/thread.cpp +++ b/3rdparty/bx/src/thread.cpp @@ -3,11 +3,11 @@ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause */ +#include "bx_p.h" #include <bx/thread.h> #if BX_PLATFORM_ANDROID \ || BX_PLATFORM_LINUX \ - || BX_PLATFORM_NACL \ || BX_PLATFORM_IOS \ || BX_PLATFORM_OSX \ || BX_PLATFORM_PS4 \ @@ -21,7 +21,6 @@ # endif // BX_PLATFORM_ #elif BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINRT \ - || BX_PLATFORM_XBOX360 \ || BX_PLATFORM_XBOXONE # include <windows.h> # include <limits.h> @@ -37,11 +36,16 @@ using namespace Windows::System::Threading; namespace bx { + static AllocatorI* getAllocator() + { + static DefaultAllocator s_allocator; + return &s_allocator; + } + struct ThreadInternal { #if BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINRT \ - || BX_PLATFORM_XBOX360 \ || BX_PLATFORM_XBOXONE static DWORD WINAPI threadFunc(LPVOID _arg); HANDLE m_handle; @@ -52,7 +56,9 @@ namespace bx #endif // BX_PLATFORM_ }; -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT +#if BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_XBOXONE \ + || BX_PLATFORM_WINRT DWORD WINAPI ThreadInternal::threadFunc(LPVOID _arg) { Thread* thread = (Thread*)_arg; @@ -76,8 +82,9 @@ namespace bx Thread::Thread() : m_fn(NULL) , m_userData(NULL) + , m_queue(getAllocator() ) , m_stackSize(0) - , m_exitCode(0 /*EXIT_SUCCESS*/) + , m_exitCode(kExitSuccess) , m_running(false) { BX_STATIC_ASSERT(sizeof(ThreadInternal) <= sizeof(m_internal) ); @@ -85,7 +92,6 @@ namespace bx ThreadInternal* ti = (ThreadInternal*)m_internal; #if BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINRT \ - || BX_PLATFORM_XBOX360 \ || BX_PLATFORM_XBOXONE ti->m_handle = INVALID_HANDLE_VALUE; ti->m_threadId = UINT32_MAX; @@ -112,7 +118,8 @@ namespace bx m_running = true; ThreadInternal* ti = (ThreadInternal*)m_internal; -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE +#if BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_XBOXONE ti->m_handle = ::CreateThread(NULL , m_stackSize , (LPTHREAD_START_ROUTINE)ti->threadFunc @@ -163,7 +170,7 @@ namespace bx { BX_CHECK(m_running, "Not running!"); ThreadInternal* ti = (ThreadInternal*)m_internal; -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS WaitForSingleObject(ti->m_handle, INFINITE); GetExitCodeThread(ti->m_handle, (DWORD*)&m_exitCode); CloseHandle(ti->m_handle); @@ -244,6 +251,17 @@ namespace bx #endif // BX_PLATFORM_ } + void Thread::push(void* _ptr) + { + m_queue.push(_ptr); + } + + void* Thread::pop() + { + void* ptr = m_queue.pop(); + return ptr; + } + int32_t Thread::entry() { #if BX_PLATFORM_WINDOWS @@ -252,7 +270,8 @@ namespace bx #endif // BX_PLATFORM_WINDOWS m_sem.post(); - return m_fn(m_userData); + int32_t result = m_fn(this, m_userData); + return result; } struct TlsDataInternal |