Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: ppapi/tests/pp_thread.h

Issue 547543002: Fix potential race-condition _beginthread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698