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

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/plugin_upcall.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
6 //
7 // This is an early draft of background thread support.
8 // Until it is complete, we assume that all proxy functions
9 // (except CallOnMainThread) are called on the main PPAPI thread.
10 //
11 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
12
13 #include "native_client/src/shared/ppapi_proxy/plugin_upcall.h"
14
15 #include <pthread.h>
16 #include <map>
17
18 #include "native_client/src/include/nacl_macros.h"
19 #include "native_client/src/include/portability.h"
20 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h"
21 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
22 #include "native_client/src/shared/ppapi_proxy/utility.h"
23 #include "native_client/src/shared/srpc/nacl_srpc.h"
24 #include "ppapi/c/pp_errors.h"
25 #include "srpcgen/ppp_rpc.h"
26 #include "srpcgen/upcall.h"
27
28 using ppapi_proxy::CompletionCallbackTable;
29
30 namespace ppapi_proxy {
31
32 namespace {
33
34 class CallOnMainThreadCriticalSection {
35 static pthread_mutex_t mutex_;
36 public:
37 CallOnMainThreadCriticalSection() { pthread_mutex_lock(&mutex_); }
38 ~CallOnMainThreadCriticalSection() { pthread_mutex_unlock(&mutex_); }
39 };
40
41 pthread_mutex_t CallOnMainThreadCriticalSection::mutex_ =
42 PTHREAD_MUTEX_INITIALIZER;
43
44 } // namespace
45
46 // The call on main thread is implemented via an RPC to the browser side on the
47 // upcall channel, instead of locally to the plugin. This is to ensure that
48 // when the callback runs (and potentially calls one of the PPB_ methods
49 // over RPC), the browser-side is listening.
50 void PluginUpcallCoreCallOnMainThread(int32_t delay_in_milliseconds,
51 PP_CompletionCallback callback,
52 int32_t result) {
53 // Force PluginUpcallCoreCallOnMainThread, from multiple threads, to occur
54 // one at a time.
55 CallOnMainThreadCriticalSection guard;
56 NaClSrpcChannel* upcall_channel = GetUpcallSrpcChannel();
57 if (upcall_channel == NULL) {
58 DebugPrintf("PluginUpcallCoreCallOnMainThread: NULL channel.\n");
59 return;
60 }
61 int32_t callback_id =
62 ppapi_proxy::CompletionCallbackTable::Get()->AddCallback(callback);
63 if (callback_id == 0) {
64 DebugPrintf("PluginUpcallCoreCallOnMainThread: NULL callback.\n");
65 return;
66 }
67 (void) PppUpcallRpcClient::PPB_Core_CallOnMainThread(
68 upcall_channel, delay_in_milliseconds, callback_id, result);
69 }
70
71 } // namespace ppapi_proxy
OLDNEW
« no previous file with comments | « ppapi/native_client/src/shared/ppapi_proxy/plugin_upcall.h ('k') | ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698