diff --git a/include/bx/config.h b/include/bx/config.h index f4650d4..fbf6e43 100644 --- a/include/bx/config.h +++ b/include/bx/config.h @@ -30,6 +30,7 @@ || BX_PLATFORM_QNX \ || BX_PLATFORM_RPI \ || BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ ? 1 : 0) #endif // BX_CONFIG_CRT_FILE_READER_WRITER @@ -38,7 +39,7 @@ #endif // BX_CONFIG_SEMAPHORE_PTHREAD #ifndef BX_CONFIG_SUPPORTS_THREADING -# define BX_CONFIG_SUPPORTS_THREADING !(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINRT) +# define BX_CONFIG_SUPPORTS_THREADING !(BX_PLATFORM_EMSCRIPTEN) #endif // BX_CONFIG_SUPPORTS_THREADING #endif // BX_CONFIG_H_HEADER_GUARD diff --git a/include/bx/sem.h b/include/bx/sem.h index dcfe654..7822257 100644 --- a/include/bx/sem.h +++ b/include/bx/sem.h @@ -202,7 +202,11 @@ namespace bx public: Semaphore() { +#if BX_PLATFORM_WINRT + m_handle = CreateSemaphoreEx(NULL, 0, LONG_MAX, NULL, 0, SEMAPHORE_ALL_ACCESS); +#else m_handle = CreateSemaphore(NULL, 0, LONG_MAX, NULL); +#endif BX_CHECK(NULL != m_handle, "Failed to create Semaphore!"); } @@ -219,7 +223,11 @@ namespace bx bool wait(int32_t _msecs = -1) const { DWORD milliseconds = (0 > _msecs) ? INFINITE : _msecs; - return WAIT_OBJECT_0 == WaitForSingleObject(m_handle, milliseconds); +#if BX_PLATFORM_WINRT + return WAIT_OBJECT_0 == WaitForSingleObjectEx(m_handle, milliseconds, FALSE); +#else + return WAIT_OBJECT_0 == WaitForSingleObject(m_handle, milliseconds); +#endif } private: diff --git a/include/bx/thread.h b/include/bx/thread.h index 79afb46..42cadc9 100644 --- a/include/bx/thread.h +++ b/include/bx/thread.h @@ -8,7 +8,11 @@ #if BX_PLATFORM_POSIX # include -#endif // BX_PLATFORM_POSIX +#elif BX_PLATFORM_WINRT +using namespace Platform; +using namespace Windows::Foundation; +using namespace Windows::System::Threading; +#endif #include "sem.h" @@ -27,7 +31,7 @@ namespace bx public: Thread() -#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT : m_handle(INVALID_HANDLE_VALUE) #elif BX_PLATFORM_POSIX : m_handle(0) @@ -65,6 +69,15 @@ namespace bx , 0 , NULL ); +#elif BX_PLATFORM_WINRT + m_handle = CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS); + auto workItemHandler = ref new WorkItemHandler([=](IAsyncAction^) + { + m_exitCode = threadFunc(this); + SetEvent(m_handle); + }, CallbackContext::Any); + + ThreadPool::RunAsync(workItemHandler, WorkItemPriority::Normal, WorkItemOptions::TimeSliced); #elif BX_PLATFORM_POSIX int result; BX_UNUSED(result); @@ -99,6 +112,10 @@ namespace bx GetExitCodeThread(m_handle, (DWORD*)&m_exitCode); CloseHandle(m_handle); m_handle = INVALID_HANDLE_VALUE; +#elif BX_PLATFORM_WINRT + WaitForSingleObjectEx(m_handle, INFINITE, FALSE); + CloseHandle(m_handle); + m_handle = INVALID_HANDLE_VALUE; #elif BX_PLATFORM_POSIX union { @@ -129,7 +146,7 @@ namespace bx return m_fn(m_userData); } -#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT static DWORD WINAPI threadFunc(LPVOID _arg) { Thread* thread = (Thread*)_arg; @@ -150,7 +167,7 @@ namespace bx } #endif // BX_PLATFORM_ -#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360 +#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360|BX_PLATFORM_WINRT HANDLE m_handle; #elif BX_PLATFORM_POSIX pthread_t m_handle; @@ -194,7 +211,7 @@ namespace bx uint32_t m_id; }; -#else +#elif !(BX_PLATFORM_WINRT) class TlsData {