ref: 2d519493687c77f5b08a32063c638b717f3075f5
parent: 371026aaf933c3ac3636933729ec84f8f871763d
parent: b35c21201ba006ddae5f10e103cc8cc03861fac7
author: volvet <[email protected]>
date: Tue Apr 1 06:52:54 EDT 2014
Merge pull request #610 from mstorsjo/wp8-threads Make threading work on windows phone
--- a/build/platform-msvc-arm.mk
+++ b/build/platform-msvc-arm.mk
@@ -2,6 +2,7 @@
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
--- a/codec/common/inc/WelsThreadLib.h
+++ b/codec/common/inc/WelsThreadLib.h
@@ -99,7 +99,6 @@
#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);
--- a/codec/common/src/WelsThreadLib.cpp
+++ b/codec/common/src/WelsThreadLib.cpp
@@ -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 @@
#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 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;
@@ -202,10 +218,6 @@
}
#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) {