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

Side by Side Diff: ppapi/tests/pp_thread.h

Issue 8764004: Add DEPS include rules so we don't accidentally use base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove rules to include self where possible Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/DEPS ('k') | ppapi/tests/test_audio_config.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 #ifndef PPAPI_TESTS_PP_THREAD_H_ 6 #ifndef PPAPI_TESTS_PP_THREAD_H_
7 #define PPAPI_TESTS_PP_THREAD_H_ 7 #define PPAPI_TESTS_PP_THREAD_H_
8 8
9 #include "ppapi/c/pp_macros.h" 9 #include "ppapi/c/pp_macros.h"
10 #include "ppapi/tests/test_utils.h"
10 11
11 /* These precompiler names were copied from chromium's build_config.h. */ 12 #if defined(PPAPI_POSIX)
12 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
13 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__)
14 #define PPAPI_HAS_POSIX_THREADS 1
15 #elif defined (_MSC_VER)
16 #define PPAPI_HAS_WINDOWS_THREADS 1
17 #endif
18
19 #if defined(PPAPI_HAS_POSIX_THREADS)
20 #include <pthread.h> 13 #include <pthread.h>
21 #elif defined(PPAPI_HAS_WINDOWS_THREADS) 14 #elif defined(PPAPI_OS_WIN)
22 #include <process.h> 15 #include <process.h>
23 #include <windows.h> 16 #include <windows.h>
17 #else
18 #error No thread library detected.
24 #endif 19 #endif
25 20
26 /** 21 /**
27 * @file 22 * @file
28 * This file provides platform-independent wrappers around threads. This is for 23 * This file provides platform-independent wrappers around threads. This is for
29 * use by PPAPI wrappers and tests which need to run on multiple platforms to 24 * use by PPAPI wrappers and tests which need to run on multiple platforms to
30 * support both trusted platforms (Windows, Mac, Linux) and untrusted (Native 25 * support both trusted platforms (Windows, Mac, Linux) and untrusted (Native
31 * Client). Apps that use PPAPI only with Native Client should generally use the 26 * Client). Apps that use PPAPI only with Native Client should generally use the
32 * Native Client POSIX implementation instead. 27 * Native Client POSIX implementation instead.
33 * 28 *
34 * TODO(dmichael): Move this file to ppapi/c and delete this comment, if we end 29 * TODO(dmichael): Move this file to ppapi/c and delete this comment, if we end
35 * up needing platform independent threads in PPAPI C or C++. This file was 30 * up needing platform independent threads in PPAPI C or C++. This file was
36 * written using inline functions and PPAPI naming conventions with the intent 31 * written using inline functions and PPAPI naming conventions with the intent
37 * of making it possible to put it in to ppapi/c. Currently, however, it's only 32 * of making it possible to put it in to ppapi/c. Currently, however, it's only
38 * used in ppapi/tests, so is not part of the published API. 33 * used in ppapi/tests, so is not part of the published API.
39 */ 34 */
40 35
41 #if defined(PPAPI_HAS_POSIX_THREADS) 36 #if defined(PPAPI_POSIX)
42 typedef pthread_t PP_ThreadType; 37 typedef pthread_t PP_ThreadType;
43 #elif defined(PPAPI_HAS_WINDOWS_THREADS) 38 #elif defined(PPAPI_OS_WIN)
44 typedef uintptr_t PP_ThreadType; 39 typedef uintptr_t PP_ThreadType;
45 #endif 40 #endif
46 41
47 typedef void (PP_ThreadFunction)(void* data); 42 typedef void (PP_ThreadFunction)(void* data);
48 43
49 PP_INLINE bool PP_CreateThread(PP_ThreadType* thread, 44 PP_INLINE bool PP_CreateThread(PP_ThreadType* thread,
50 PP_ThreadFunction function, 45 PP_ThreadFunction function,
51 void* thread_arg); 46 void* thread_arg);
52 PP_INLINE void PP_JoinThread(PP_ThreadType thread); 47 PP_INLINE void PP_JoinThread(PP_ThreadType thread);
53 48
54 #if defined(PPAPI_HAS_POSIX_THREADS) 49 #if defined(PPAPI_POSIX)
55 /* Because POSIX thread functions return void* and Windows thread functions do 50 /* Because POSIX thread functions return void* and Windows thread functions do
56 * not, we make PPAPI thread functions have the least capability (no returns). 51 * not, we make PPAPI thread functions have the least capability (no returns).
57 * This struct wraps the user data & function so that we can use the correct 52 * This struct wraps the user data & function so that we can use the correct
58 * function type on POSIX platforms. 53 * function type on POSIX platforms.
59 */ 54 */
60 struct PP_ThreadFunctionArgWrapper { 55 struct PP_ThreadFunctionArgWrapper {
61 void* user_data; 56 void* user_data;
62 PP_ThreadFunction* user_function; 57 PP_ThreadFunction* user_function;
63 }; 58 };
64 59
(...skipping 16 matching lines...) Expand all
81 NULL, 76 NULL,
82 PP_POSIXThreadFunctionThunk, 77 PP_POSIXThreadFunctionThunk,
83 arg_wrapper) == 0); 78 arg_wrapper) == 0);
84 } 79 }
85 80
86 PP_INLINE void PP_JoinThread(PP_ThreadType thread) { 81 PP_INLINE void PP_JoinThread(PP_ThreadType thread) {
87 void* exit_status; 82 void* exit_status;
88 pthread_join(thread, &exit_status); 83 pthread_join(thread, &exit_status);
89 } 84 }
90 85
91 #elif defined(PPAPI_HAS_WINDOWS_THREADS) 86 #elif defined(PPAPI_OS_WIN)
92 typedef DWORD (PP_WindowsThreadFunction)(void* data); 87 typedef DWORD (PP_WindowsThreadFunction)(void* data);
93 88
94 PP_INLINE bool PP_CreateThread(PP_ThreadType* thread, 89 PP_INLINE bool PP_CreateThread(PP_ThreadType* thread,
95 PP_ThreadFunction function, 90 PP_ThreadFunction function,
96 void* thread_arg) { 91 void* thread_arg) {
97 if (!thread) 92 if (!thread)
98 return false; 93 return false;
99 *thread = ::_beginthread(function, 94 *thread = ::_beginthread(function,
100 0, /* Use default stack size. */ 95 0, /* Use default stack size. */
101 thread_arg); 96 thread_arg);
102 return (*thread != NULL); 97 return (*thread != NULL);
103 } 98 }
104 99
105 PP_INLINE void PP_JoinThread(PP_ThreadType thread) { 100 PP_INLINE void PP_JoinThread(PP_ThreadType thread) {
106 ::WaitForSingleObject((HANDLE)thread, INFINITE); 101 ::WaitForSingleObject((HANDLE)thread, INFINITE);
107 } 102 }
108 103
109 #endif 104 #endif
110 105
111 106
112 /** 107 /**
113 * @} 108 * @}
114 */ 109 */
115 110
116 #endif /* PPAPI_TESTS_PP_THREAD_H_ */ 111 #endif /* PPAPI_TESTS_PP_THREAD_H_ */
117 112
OLDNEW
« no previous file with comments | « ppapi/tests/DEPS ('k') | ppapi/tests/test_audio_config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698