History

Use the Windows Runtime ThreadPool API for creating threads on Windows Phone

Windows Phone lacks the old CreateThread/beginthreadex APIs for creating threads. (Technically, the functions still do exist, but they aren't officially supported and aren't visible in the headers when targeting Windows Phone.) Building code that uses the Windows Runtime language extensions requires building with the -ZW option.

Martin Storsjö committed 12 years ago

Commit b35c2121 parent f293d262 files · +17 −0Browse files

Showing the changes to codec/common/src/WelsThreadLib.cpp (1 of 2 files). Show all

Unified · Split

codec/common/src/WelsThreadLib.cpp+16−0
@@ -68,6 +68,11 @@ · 67 unmodified lines
68 68
69#ifdef WINAPI_FAMILY69#ifdef WINAPI_FAMILY
70#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)70#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
71using namespace Platform;
72using namespace Windows::Foundation;
73using namespace Windows::System::Threading;
74#define USE_THREADPOOL
75
71#define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0, 0)76#define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0, 0)
72#define GetSystemInfo(x) GetNativeSystemInfo(x)77#define GetSystemInfo(x) GetNativeSystemInfo(x)
73#define CreateEvent(attr, reset, init, name) CreateEventEx(attr, name, ((reset) ? CREATE_EVENT_MANUAL_RESET : 0) | ((init) ? CREATE_EVENT_INITIAL_SET : 0), EVENT_ALL_ACCESS)78#define CreateEvent(attr, reset, init, name) CreateEventEx(attr, name, ((reset) ? CREATE_EVENT_MANUAL_RESET : 0) | ((init) ? CREATE_EVENT_INITIAL_SET : 0), EVENT_ALL_ACCESS)
@@ -169,7 +174,18 @@ WELS_THREAD_ERROR_CODE WelsEventClose (WELS_EVENT* event, const char* event_n · 95 unmodified lines
169 174
170WELS_THREAD_ERROR_CODE WelsThreadCreate (WELS_THREAD_HANDLE* thread, LPWELS_THREAD_ROUTINE routine,175WELS_THREAD_ERROR_CODE WelsThreadCreate (WELS_THREAD_HANDLE* thread, LPWELS_THREAD_ROUTINE routine,
171 void* arg, WELS_THREAD_ATTR attr) {176 void* arg, WELS_THREAD_ATTR attr) {
177#ifdef USE_THREADPOOL
178 HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
179 HANDLE h2;
180 DuplicateHandle(GetCurrentProcess(), h, GetCurrentProcess(), &h2, 0, FALSE, DUPLICATE_SAME_ACCESS);
181 ThreadPool::RunAsync(ref new WorkItemHandler([=](IAsyncAction^) {
182 routine(arg);
183 SetEvent(h2);
184 CloseHandle(h2);
185 }, CallbackContext::Any), WorkItemPriority::Normal, WorkItemOptions::TimeSliced);
186#else
172 WELS_THREAD_HANDLE h = CreateThread (NULL, 0, routine, arg, 0, NULL);187 WELS_THREAD_HANDLE h = CreateThread (NULL, 0, routine, arg, 0, NULL);
188#endif
173 189
174 if (h == NULL) {190 if (h == NULL) {
175 return WELS_THREAD_ERROR_GENERAL;191 return WELS_THREAD_ERROR_GENERAL;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t