mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Adding WinRT threading support.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
|
||||
#if BX_PLATFORM_POSIX
|
||||
# include <pthread.h>
|
||||
#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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user