Merge pull request #610 from mstorsjo/wp8-threads

Make threading work on windows phone
This commit is contained in:
volvet 2014-04-01 10:52:54 -07:00
commit 2d51949368
3 changed files with 21 additions and 9 deletions

View File

@ -2,6 +2,7 @@ include build/platform-msvc-common.mk
ARCH=arm
include build/platform-arch.mk
CFLAGS += -DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP -MD -DWIN32
CXXFLAGS += -ZW
LDFLAGS +=
CCAS = gas-preprocessor.pl -as-type armasm -force-thumb -- armasm

View File

@ -99,7 +99,6 @@ typedef struct _WelsLogicalProcessorInfo {
#define WELS_THREAD_ERROR_WAIT_TIMEOUT ((uint32_t)0x00000102L)
#define WELS_THREAD_ERROR_WAIT_FAILED WELS_THREAD_ERROR_GENERAL
void WelsSleep (uint32_t dwMilliseconds);
WELS_THREAD_ERROR_CODE WelsMutexInit (WELS_MUTEX* mutex);
WELS_THREAD_ERROR_CODE WelsMutexLock (WELS_MUTEX* mutex);
WELS_THREAD_ERROR_CODE WelsMutexUnlock (WELS_MUTEX* mutex);

View File

@ -68,7 +68,16 @@
#ifdef WINAPI_FAMILY
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::System::Threading;
#define USE_THREADPOOL
#define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0, 0)
#define GetSystemInfo(x) GetNativeSystemInfo(x)
#define CreateEvent(attr, reset, init, name) CreateEventEx(attr, name, ((reset) ? CREATE_EVENT_MANUAL_RESET : 0) | ((init) ? CREATE_EVENT_INITIAL_SET : 0), EVENT_ALL_ACCESS)
#define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE)
#define WaitForMultipleObjects(a, b, c, d) WaitForMultipleObjectsEx(a, b, c, d, FALSE)
#endif
#endif
@ -118,10 +127,6 @@ WELS_THREAD_ERROR_CODE WelsMutexDestroy (WELS_MUTEX* mutex) {
#ifdef _WIN32
void WelsSleep (uint32_t dwMilliseconds) {
Sleep (dwMilliseconds);
}
WELS_THREAD_ERROR_CODE WelsEventOpen (WELS_EVENT* event, const char* event_name) {
WELS_EVENT h = CreateEvent (NULL, FALSE, FALSE, NULL);
@ -169,7 +174,18 @@ WELS_THREAD_ERROR_CODE WelsEventClose (WELS_EVENT* event, const char* event_n
WELS_THREAD_ERROR_CODE WelsThreadCreate (WELS_THREAD_HANDLE* thread, LPWELS_THREAD_ROUTINE routine,
void* arg, WELS_THREAD_ATTR attr) {
#ifdef USE_THREADPOOL
HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
HANDLE h2;
DuplicateHandle(GetCurrentProcess(), h, GetCurrentProcess(), &h2, 0, FALSE, DUPLICATE_SAME_ACCESS);
ThreadPool::RunAsync(ref new WorkItemHandler([=](IAsyncAction^) {
routine(arg);
SetEvent(h2);
CloseHandle(h2);
}, CallbackContext::Any), WorkItemPriority::Normal, WorkItemOptions::TimeSliced);
#else
WELS_THREAD_HANDLE h = CreateThread (NULL, 0, routine, arg, 0, NULL);
#endif
if (h == NULL) {
return WELS_THREAD_ERROR_GENERAL;
@ -203,10 +219,6 @@ WELS_THREAD_ERROR_CODE WelsQueryLogicalProcessInfo (WelsLogicalProcessInfo* p
#else
void WelsSleep (uint32_t dwMilliseconds) {
usleep (dwMilliseconds * 1000); // microseconds
}
WELS_THREAD_ERROR_CODE WelsThreadCreate (WELS_THREAD_HANDLE* thread, LPWELS_THREAD_ROUTINE routine,
void* arg, WELS_THREAD_ATTR attr) {
WELS_THREAD_ERROR_CODE err = 0;