| Index: ppapi/tests/pp_thread.h
|
| diff --git a/ppapi/tests/pp_thread.h b/ppapi/tests/pp_thread.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9bc7da1b7410ece5644af59984c54e3f67a9a9b5
|
| --- /dev/null
|
| +++ b/ppapi/tests/pp_thread.h
|
| @@ -0,0 +1,99 @@
|
| +/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +/* From pp_thread.idl modified Mon Jul 18 17:53:53 2011. */
|
| +
|
| +#ifndef PPAPI_TESTS_PP_THREAD_H_
|
| +#define PPAPI_TESTS_PP_THREAD_H_
|
| +
|
| +#include "ppapi/c/pp_macros.h"
|
| +
|
| +/**
|
| + * @file
|
| + * This file provides platform-independent wrappers around threads.
|
| + */
|
| +#if defined(PPAPI_HAS_POSIX_THREADS)
|
| +#include <pthread.h>
|
| +#elif defined(PPAPI_HAS_WINDOWS_THREADS)
|
| +#include <process.h>
|
| +#include <windows.h>
|
| +#endif
|
| +
|
| +#if defined(PPAPI_HAS_POSIX_THREADS)
|
| +typedef pthread_t PP_ThreadType;
|
| +#elif defined(PPAPI_HAS_WINDOWS_THREADS)
|
| +typedef uintptr_t PP_ThreadType;
|
| +#endif
|
| +
|
| +typedef void (PP_ThreadFunction)(void* data);
|
| +
|
| +PP_INLINE bool PP_CreateThread(PP_ThreadType* thread,
|
| + PP_ThreadFunction function,
|
| + void* thread_arg);
|
| +PP_INLINE void PP_JoinThread(PP_ThreadType thread);
|
| +
|
| +#if defined(PPAPI_HAS_POSIX_THREADS)
|
| +/* Because POSIX thread functions return void* and Windows thread functions do
|
| + * not, we make PPAPI thread functions have the least capability (no returns).
|
| + * This struct wraps the user data & function so that we can use the correct
|
| + * function type on POSIX platforms.
|
| + */
|
| +struct PP_ThreadFunctionArgWrapper {
|
| + void* user_data;
|
| + PP_ThreadFunction* user_function;
|
| +};
|
| +
|
| +PP_INLINE void* PP_POSIXThreadFunctionThunk(void* param) {
|
| + PP_ThreadFunctionArgWrapper* arg_wrapper =
|
| + (PP_ThreadFunctionArgWrapper*)param;
|
| + arg_wrapper->user_function(arg_wrapper->user_data);
|
| + free(param);
|
| + return NULL;
|
| +}
|
| +
|
| +PP_INLINE bool PP_CreateThread(PP_ThreadType* thread,
|
| + PP_ThreadFunction function,
|
| + void* thread_arg) {
|
| + PP_ThreadFunctionArgWrapper* arg_wrapper =
|
| + (PP_ThreadFunctionArgWrapper*)malloc(sizeof(PP_ThreadFunctionArgWrapper));
|
| + arg_wrapper->user_function = function;
|
| + arg_wrapper->user_data = thread_arg;
|
| + return (pthread_create((pthread_t*)thread,
|
| + NULL,
|
| + PP_POSIXThreadFunctionThunk,
|
| + arg_wrapper) == 0);
|
| +}
|
| +
|
| +PP_INLINE void PP_JoinThread(PP_ThreadType thread) {
|
| + void* exit_status;
|
| + pthread_join(thread, &exit_status);
|
| +}
|
| +
|
| +#elif defined(PPAPI_HAS_WINDOWS_THREADS)
|
| +typedef DWORD (PP_WindowsThreadFunction)(void* data);
|
| +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);
|
| +}
|
| +
|
| +PP_INLINE void PP_JoinThread(PP_ThreadType thread) {
|
| + ::WaitForSingleObject((HANDLE)thread, INFINITE);
|
| +}
|
| +
|
| +#endif
|
| +
|
| +
|
| +/**
|
| + * @}
|
| + */
|
| +
|
| +#endif /* PPAPI_TESTS_PP_THREAD_H_ */
|
| +
|
|
|