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

Side by Side Diff: mojo/edk/system/core.h

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to mojo::edk namespace in preparation for runtim flag Created 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef MOJO_EDK_SYSTEM_CORE_H_ 5 #ifndef MOJO_EDK_SYSTEM_CORE_H_
6 #define MOJO_EDK_SYSTEM_CORE_H_ 6 #define MOJO_EDK_SYSTEM_CORE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/synchronization/lock.h"
13 #include "mojo/edk/system/handle_table.h" 14 #include "mojo/edk/system/handle_table.h"
14 #include "mojo/edk/system/mapping_table.h" 15 #include "mojo/edk/system/mapping_table.h"
15 #include "mojo/edk/system/memory.h" 16 #include "mojo/edk/system/memory.h"
16 #include "mojo/edk/system/mutex.h"
17 #include "mojo/edk/system/system_impl_export.h" 17 #include "mojo/edk/system/system_impl_export.h"
18 #include "mojo/public/c/system/buffer.h" 18 #include "mojo/public/c/system/buffer.h"
19 #include "mojo/public/c/system/data_pipe.h" 19 #include "mojo/public/c/system/data_pipe.h"
20 #include "mojo/public/c/system/message_pipe.h" 20 #include "mojo/public/c/system/message_pipe.h"
21 #include "mojo/public/c/system/types.h" 21 #include "mojo/public/c/system/types.h"
22 #include "mojo/public/cpp/system/macros.h" 22 #include "mojo/public/cpp/system/macros.h"
23 23
24 namespace mojo { 24 namespace mojo {
25 25
26 namespace embedder { 26 namespace edk {
27 class PlatformSupport;
28 }
29
30 namespace system {
31 27
32 class Dispatcher; 28 class Dispatcher;
29 class PlatformSupport;
33 struct HandleSignalsState; 30 struct HandleSignalsState;
34 31
35 // |Core| is an object that implements the Mojo system calls. All public methods 32 // |Core| is an object that implements the Mojo system calls. All public methods
36 // are thread-safe. 33 // are thread-safe.
37 class MOJO_SYSTEM_IMPL_EXPORT Core { 34 class MOJO_SYSTEM_IMPL_EXPORT Core {
38 public: 35 public:
39 // --------------------------------------------------------------------------- 36 // ---------------------------------------------------------------------------
40 37
41 // These methods are only to be used by via the embedder API (and internally): 38 // These methods are only to be used by via the embedder API (and internally):
42 39
43 // |*platform_support| must outlive this object. 40 // |*platform_support| must outlive this object.
44 explicit Core(embedder::PlatformSupport* platform_support); 41 explicit Core(PlatformSupport* platform_support);
45 virtual ~Core(); 42 virtual ~Core();
46 43
47 // Adds |dispatcher| to the handle table, returning the handle for it. Returns 44 // Adds |dispatcher| to the handle table, returning the handle for it. Returns
48 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full. 45 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full.
49 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); 46 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher);
50 47
51 // Looks up the dispatcher for the given handle. Returns null if the handle is 48 // Looks up the dispatcher for the given handle. Returns null if the handle is
52 // invalid. 49 // invalid.
53 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); 50 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle);
54 51
55 // Like |GetDispatcher()|, but also removes the handle from the handle table. 52 // Like |GetDispatcher()|, but also removes the handle from the handle table.
56 // On success, gets the dispatcher for a given handle (which should not be 53 // On success, gets the dispatcher for a given handle (which should not be
57 // |MOJO_HANDLE_INVALID|) and removes it. (On failure, returns an appropriate 54 // |MOJO_HANDLE_INVALID|) and removes it. (On failure, returns an appropriate
58 // result (and leaves |dispatcher| alone), namely 55 // result (and leaves |dispatcher| alone), namely
59 // |MOJO_RESULT_INVALID_ARGUMENT| if there's no dispatcher for the given 56 // |MOJO_RESULT_INVALID_ARGUMENT| if there's no dispatcher for the given
60 // handle or |MOJO_RESULT_BUSY| if the handle is marked as busy.) 57 // handle or |MOJO_RESULT_BUSY| if the handle is marked as busy.)
61 MojoResult GetAndRemoveDispatcher(MojoHandle handle, 58 MojoResult GetAndRemoveDispatcher(MojoHandle handle,
62 scoped_refptr<Dispatcher>* dispatcher); 59 scoped_refptr<Dispatcher>* dispatcher);
63 60
64 // Watches on the given handle for the given signals, calling |callback| when 61 // Watches on the given handle for the given signals, calling |callback| when
65 // a signal is satisfied or when all signals become unsatisfiable. |callback| 62 // a signal is satisfied or when all signals become unsatisfiable. |callback|
66 // must satisfy stringent requirements -- see |Awakable::Awake()| in 63 // must satisfy stringent requirements -- see |Awakable::Awake()| in
67 // awakable.h. In particular, it must not call any Mojo system functions. 64 // awakable.h. In particular, it must not call any Mojo system functions.
68 MojoResult AsyncWait(MojoHandle handle, 65 MojoResult AsyncWait(MojoHandle handle,
69 MojoHandleSignals signals, 66 MojoHandleSignals signals,
70 const base::Callback<void(MojoResult)>& callback); 67 const base::Callback<void(MojoResult)>& callback);
71 68
72 embedder::PlatformSupport* platform_support() const { 69 PlatformSupport* platform_support() const {
73 return platform_support_; 70 return platform_support_;
74 } 71 }
75 72
76 // --------------------------------------------------------------------------- 73 // ---------------------------------------------------------------------------
77 74
78 // The following methods are essentially implementations of the Mojo Core 75 // The following methods are essentially implementations of the Mojo Core
79 // functions of the Mojo API, with the C interface translated to C++ by 76 // functions of the Mojo API, with the C interface translated to C++ by
80 // "mojo/edk/embedder/entrypoints.cc". The best way to understand the contract 77 // "mojo/edk/embedder/entrypoints.cc". The best way to understand the contract
81 // of these methods is to look at the header files defining the corresponding 78 // of these methods is to look at the header files defining the corresponding
82 // API functions, referenced below. 79 // API functions, referenced below.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // validation of arguments. |*result_index| is only set if the result (whether 163 // validation of arguments. |*result_index| is only set if the result (whether
167 // success or failure) applies to a specific handle, so its value should be 164 // success or failure) applies to a specific handle, so its value should be
168 // preinitialized to |static_cast<uint32_t>(-1)|. 165 // preinitialized to |static_cast<uint32_t>(-1)|.
169 MojoResult WaitManyInternal(const MojoHandle* handles, 166 MojoResult WaitManyInternal(const MojoHandle* handles,
170 const MojoHandleSignals* signals, 167 const MojoHandleSignals* signals,
171 uint32_t num_handles, 168 uint32_t num_handles,
172 MojoDeadline deadline, 169 MojoDeadline deadline,
173 uint32_t* result_index, 170 uint32_t* result_index,
174 HandleSignalsState* signals_states); 171 HandleSignalsState* signals_states);
175 172
176 embedder::PlatformSupport* const platform_support_; 173 PlatformSupport* const platform_support_;
177 174
178 // TODO(vtl): |handle_table_mutex_| should be a reader-writer lock (if only we 175 // TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we
179 // had them). 176 // had them).
180 Mutex handle_table_mutex_; 177 base::Lock handle_table_lock_; // Protects |handle_table_|.
181 HandleTable handle_table_ MOJO_GUARDED_BY(handle_table_mutex_); 178 HandleTable handle_table_;
182 179
183 Mutex mapping_table_mutex_; 180 base::Lock mapping_table_lock_; // Protects |mapping_table_|.
184 MappingTable mapping_table_ MOJO_GUARDED_BY(mapping_table_mutex_); 181 MappingTable mapping_table_;
185 182
186 MOJO_DISALLOW_COPY_AND_ASSIGN(Core); 183 MOJO_DISALLOW_COPY_AND_ASSIGN(Core);
187 }; 184 };
188 185
189 } // namespace system 186 } // namespace edk
190 } // namespace mojo 187 } // namespace mojo
191 188
192 #endif // MOJO_EDK_SYSTEM_CORE_H_ 189 #endif // MOJO_EDK_SYSTEM_CORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698