OLD | NEW |
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 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 /* From ppb_message_loop.idl modified Thu Jan 17 12:04:14 2013. */ | 6 /* From ppb_message_loop.idl modified Thu Mar 28 11:08:46 2013. */ |
7 | 7 |
8 #ifndef PPAPI_C_PPB_MESSAGE_LOOP_H_ | 8 #ifndef PPAPI_C_PPB_MESSAGE_LOOP_H_ |
9 #define PPAPI_C_PPB_MESSAGE_LOOP_H_ | 9 #define PPAPI_C_PPB_MESSAGE_LOOP_H_ |
10 | 10 |
11 #include "ppapi/c/pp_bool.h" | 11 #include "ppapi/c/pp_bool.h" |
12 #include "ppapi/c/pp_completion_callback.h" | 12 #include "ppapi/c/pp_completion_callback.h" |
13 #include "ppapi/c/pp_instance.h" | 13 #include "ppapi/c/pp_instance.h" |
14 #include "ppapi/c/pp_macros.h" | 14 #include "ppapi/c/pp_macros.h" |
15 #include "ppapi/c/pp_resource.h" | 15 #include "ppapi/c/pp_resource.h" |
16 #include "ppapi/c/pp_stdint.h" | 16 #include "ppapi/c/pp_stdint.h" |
(...skipping 17 matching lines...) Expand all Loading... |
34 * allows you to post work to the message loop for a thread. | 34 * allows you to post work to the message loop for a thread. |
35 * | 35 * |
36 * To process work posted to the message loop, as well as completion callbacks | 36 * To process work posted to the message loop, as well as completion callbacks |
37 * for asynchronous operations, you must run the message loop via Run(). | 37 * for asynchronous operations, you must run the message loop via Run(). |
38 * | 38 * |
39 * Note the system manages the lifetime of the instance (and all associated | 39 * Note the system manages the lifetime of the instance (and all associated |
40 * resources). If the instance is deleted from the page, background threads may | 40 * resources). If the instance is deleted from the page, background threads may |
41 * suddenly see their PP_Resource handles become invalid. In this case, calls | 41 * suddenly see their PP_Resource handles become invalid. In this case, calls |
42 * will fail with PP_ERROR_BADRESOURCE. If you need to access data associated | 42 * will fail with PP_ERROR_BADRESOURCE. If you need to access data associated |
43 * with your instance, you will probably want to create some kind of threadsafe | 43 * with your instance, you will probably want to create some kind of threadsafe |
44 * proxy object that can handle asynchonous destruction of the instance object. | 44 * proxy object that can handle asynchronous destruction of the instance object. |
45 * | 45 * |
46 * Typical usage: | 46 * Typical usage: |
47 * On the main thread: | 47 * On the main thread: |
48 * - Create the thread yourself (using pthreads). | 48 * - Create the thread yourself (using pthreads). |
49 * - Create the message loop resource. | 49 * - Create the message loop resource. |
50 * - Pass the message loop resource to your thread's main function. | 50 * - Pass the message loop resource to your thread's main function. |
51 * - Call PostWork() on the message loop to run functions on the thread. | 51 * - Call PostWork() on the message loop to run functions on the thread. |
52 * | 52 * |
53 * From the background thread's main function: | 53 * From the background thread's main function: |
54 * - Call AttachToCurrentThread() with the message loop resource. | 54 * - Call AttachToCurrentThread() with the message loop resource. |
55 * - Call Run() with the message loop resource. | 55 * - Call Run() with the message loop resource. |
56 * | 56 * |
57 * Your callacks should look like this: | 57 * Your callbacks should look like this: |
58 * void DoMyWork(void* user_data, int32_t status) { | 58 * void DoMyWork(void* user_data, int32_t status) { |
59 * if (status != PP_OK) { | 59 * if (status != PP_OK) { |
60 * Cleanup(); // e.g. free user_data. | 60 * Cleanup(); // e.g. free user_data. |
61 * return; | 61 * return; |
62 * } | 62 * } |
63 * ... do your work... | 63 * ... do your work... |
64 * } | 64 * } |
65 * For a C++ example, see ppapi/utility/threading/simple_thread.h | 65 * For a C++ example, see ppapi/utility/threading/simple_thread.h |
66 * | 66 * |
67 * (You can also create the message loop resource on the background thread, | 67 * (You can also create the message loop resource on the background thread, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 int32_t (*Run)(PP_Resource message_loop); | 212 int32_t (*Run)(PP_Resource message_loop); |
213 /** | 213 /** |
214 * Schedules work to run on the given message loop. This may be called from | 214 * Schedules work to run on the given message loop. This may be called from |
215 * any thread. Posted work will be executed in the order it was posted when | 215 * any thread. Posted work will be executed in the order it was posted when |
216 * the message loop is Run(). | 216 * the message loop is Run(). |
217 * | 217 * |
218 * @param message_loop The message loop resource. | 218 * @param message_loop The message loop resource. |
219 * | 219 * |
220 * @param callback The completion callback to execute from the message loop. | 220 * @param callback The completion callback to execute from the message loop. |
221 * | 221 * |
222 * @param delay_ms The number of millseconds to delay execution of the given | 222 * @param delay_ms The number of milliseconds to delay execution of the given |
223 * completion callback. Passing 0 means it will get queued normally and | 223 * completion callback. Passing 0 means it will get queued normally and |
224 * executed in order. | 224 * executed in order. |
225 * | 225 * |
226 * | 226 * |
227 * The completion callback will be called with PP_OK as the "result" parameter | 227 * The completion callback will be called with PP_OK as the "result" parameter |
228 * if it is run normally. It is good practice to check for PP_OK and return | 228 * if it is run normally. It is good practice to check for PP_OK and return |
229 * early otherwise. | 229 * early otherwise. |
230 * | 230 * |
231 * The "required" flag on the completion callback is ignored. If there is an | 231 * The "required" flag on the completion callback is ignored. If there is an |
232 * error posting your callback, the error will be returned from PostWork and | 232 * error posting your callback, the error will be returned from PostWork and |
233 * the callback will never be run (because there is no appropriate place to | 233 * the callback will never be run (because there is no appropriate place to |
234 * run your callback with an error without causing unexpected threading | 234 * run your callback with an error without causing unexpected threading |
235 * problems). If you associate memory with the completion callback (for | 235 * problems). If you associate memory with the completion callback (for |
236 * example, you're using the C++ CompletionCallbackFactory), you will need to | 236 * example, you're using the C++ CompletionCallbackFactory), you will need to |
237 * free this or manually run the callback. See "Desctruction and error | 237 * free this or manually run the callback. See "Destruction and error |
238 * handling" above. | 238 * handling" above. |
239 * | 239 * |
240 * | 240 * |
241 * You can call this function before the message loop has started and the | 241 * You can call this function before the message loop has started and the |
242 * work will get queued until the message loop is run. You can also post | 242 * work will get queued until the message loop is run. You can also post |
243 * work after the message loop has exited as long as should_destroy was | 243 * work after the message loop has exited as long as should_destroy was |
244 * PP_FALSE. It will be queued until the next invocation of Run(). | 244 * PP_FALSE. It will be queued until the next invocation of Run(). |
245 * | 245 * |
246 * @return | 246 * @return |
247 * - PP_OK: The work was posted to the message loop's queue. As described | 247 * - PP_OK: The work was posted to the message loop's queue. As described |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 int32_t (*PostQuit)(PP_Resource message_loop, PP_Bool should_destroy); | 280 int32_t (*PostQuit)(PP_Resource message_loop, PP_Bool should_destroy); |
281 }; | 281 }; |
282 | 282 |
283 typedef struct PPB_MessageLoop_1_0 PPB_MessageLoop; | 283 typedef struct PPB_MessageLoop_1_0 PPB_MessageLoop; |
284 /** | 284 /** |
285 * @} | 285 * @} |
286 */ | 286 */ |
287 | 287 |
288 #endif /* PPAPI_C_PPB_MESSAGE_LOOP_H_ */ | 288 #endif /* PPAPI_C_PPB_MESSAGE_LOOP_H_ */ |
289 | 289 |
OLD | NEW |