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

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/browser_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, 4 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) 2010 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 functions proxy functions
9 // (but CallOnMainThread) are called on the main thread.
10 //
11 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
12 //
13 // Support for "upcalls" -- RPCs to the browser that are done from other than
14 // the main thread. These calls are synchronized by the ppapi_proxy library
15 // at the plugin end.
16
17 #include "native_client/src/shared/ppapi_proxy/browser_upcall.h"
18
19 #include <new>
20
21 #include "native_client/src/include/portability.h"
22 #include "native_client/src/include/nacl_macros.h"
23 #include "native_client/src/include/nacl_scoped_ptr.h"
24 #include "native_client/src/shared/platform/nacl_threads.h"
25 #include "native_client/src/shared/ppapi_proxy/browser_callback.h"
26 #include "native_client/src/shared/ppapi_proxy/browser_globals.h"
27 #include "native_client/src/shared/ppapi_proxy/utility.h"
28 #include "native_client/src/shared/srpc/nacl_srpc.h"
29 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
30 #include "ppapi/c/pp_completion_callback.h"
31 #include "ppapi/c/pp_errors.h"
32 #include "ppapi/c/ppb_core.h"
33 #include "srpcgen/upcall.h"
34
35 using nacl::DescWrapper;
36 using nacl::DescWrapperFactory;
37
38 namespace {
39
40 // Structure for passing information to the thread. Shares ownership of
41 // the descriptor with the creating routine. This allows passing ownership
42 // to the upcall thread.
43 struct UpcallInfo {
44 nacl::scoped_ptr<DescWrapper> wrapper;
45 NaClSrpcChannel* channel;
46 };
47
48 void WINAPI UpcallThread(void* arg) {
49 // The memory for info was allocated on the creating (browser UI) thread,
50 // but ownership was conferred to the upcall thread for deletion.
51 nacl::scoped_ptr<UpcallInfo> info(reinterpret_cast<UpcallInfo*>(arg));
52 NaClSrpcServerLoop(info->wrapper->desc(),
53 PpbUpcalls::srpc_methods,
54 info->channel);
55 }
56
57 } // namespace
58
59 namespace ppapi_proxy {
60
61 DescWrapper* BrowserUpcall::Start(struct NaClThread* nacl_thread,
62 NaClSrpcChannel* upcall_channel) {
63 // Create a socket pair for the upcall server.
64 DescWrapperFactory factory;
65 DescWrapper* pair[2] = { NULL, NULL };
66 if (factory.MakeSocketPair(pair)) {
67 return NULL;
68 }
69 nacl::scoped_ptr<DescWrapper> browser_end(pair[0]);
70 nacl::scoped_ptr<DescWrapper> plugin_end(pair[1]);
71 // Create an info node to pass to the thread.
72 nacl::scoped_ptr<UpcallInfo> info(new UpcallInfo);
73 info->wrapper.reset(browser_end.get());
74 info->channel = upcall_channel;
75 // On success, info took ownership of browser_end.
76 browser_end.release();
77 // Create a thread and an SRPC "upcall" server.
78 const int kThreadStackSize = 128 * 1024;
79 if (!NaClThreadCreateJoinable(nacl_thread,
80 UpcallThread,
81 info.get(),
82 kThreadStackSize)) {
83 return NULL;
84 }
85 // On successful thread creation, ownership of info passes to the thread.
86 info.release();
87 // On successful return, the caller gets the plugin_end of the socketpair.
88 return plugin_end.release();
89 }
90
91 } // namespace ppapi_proxy
OLDNEW
« no previous file with comments | « ppapi/native_client/src/shared/ppapi_proxy/browser_upcall.h ('k') | ppapi/native_client/src/shared/ppapi_proxy/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698