Index: ppapi/tests/pp_thread.h |
diff --git a/ppapi/tests/pp_thread.h b/ppapi/tests/pp_thread.h |
index c4af8f1bbf1094d95c06d2b4519577c23fc60d9c..4a8d2378970521e63c604fba6781ae2323db164a 100644 |
--- a/ppapi/tests/pp_thread.h |
+++ b/ppapi/tests/pp_thread.h |
@@ -33,14 +33,18 @@ |
* used in ppapi/tests, so is not part of the published API. |
*/ |
+typedef void (PP_ThreadFunction)(void* data); |
+ |
#if defined(PPAPI_POSIX) |
typedef pthread_t PP_ThreadType; |
#elif defined(PPAPI_OS_WIN) |
-typedef uintptr_t PP_ThreadType; |
+struct PP_ThreadType { |
bbudge
2014/09/05 17:22:59
Given that this is now a struct, PP_ThreadType doe
|
+ HANDLE handle; |
+ PP_ThreadFunction* thread_func; |
+ void* thread_arg; |
+}; |
#endif |
-typedef void (PP_ThreadFunction)(void* data); |
- |
PP_INLINE bool PP_CreateThread(PP_ThreadType* thread, |
PP_ThreadFunction function, |
void* thread_arg); |
@@ -86,19 +90,32 @@ PP_INLINE void PP_JoinThread(PP_ThreadType thread) { |
#elif defined(PPAPI_OS_WIN) |
typedef DWORD (PP_WindowsThreadFunction)(void* data); |
bbudge
2014/09/05 17:22:59
This typedef doesn't appear to be used anywhere.
|
+PP_INLINE unsigned int __stdcall ProxyThreadFunc(void* param) { |
bbudge
2014/09/05 17:22:59
This is really an adapter or 'thunk' for the threa
|
+ PP_ThreadType* params = reinterpret_cast<PP_ThreadType*>(param); |
+ params->thread_func(params->thread_arg); |
+ return 0; |
+} |
+ |
PP_INLINE bool PP_CreateThread(PP_ThreadType* thread, |
PP_ThreadFunction function, |
void* thread_arg) { |
if (!thread) |
return false; |
- *thread = ::_beginthread(function, |
- 0, /* Use default stack size. */ |
- thread_arg); |
- return (*thread != NULL); |
+ thread->thread_func = function; |
+ thread->thread_arg = thread_arg; |
+ uintptr_t raw_handle = ::_beginthreadex(NULL, |
+ 0, /* Use default stack size. */ |
bbudge
2014/09/05 17:22:59
nit: indent is strange
|
+ &ProxyThreadFunc, |
+ thread, |
+ 0, |
+ NULL); |
+ thread->handle = reinterpret_cast<HANDLE>(raw_handle); |
+ return (thread->handle != NULL); |
} |
-PP_INLINE void PP_JoinThread(PP_ThreadType thread) { |
- ::WaitForSingleObject((HANDLE)thread, INFINITE); |
+PP_INLINE void PP_JoinThread(PP_ThreadType thread_info) { |
+ ::WaitForSingleObject(thread_info.handle, INFINITE); |
+ ::CloseHandle(thread_info.handle); |
} |
#endif |