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

Side by Side Diff: mojo/public/cpp/bindings/lib/multiplex_router.h

Issue 2345013002: Mojo C++ bindings: remove the lock in MultiplexRouter if it only serves a single interface. (Closed)
Patch Set: . Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // while the others are safe to call from any threads. Please see the method 49 // while the others are safe to call from any threads. Please see the method
50 // comments for more details. 50 // comments for more details.
51 // 51 //
52 // NOTE: CloseMessagePipe() or PassMessagePipe() MUST be called on |runner|'s 52 // NOTE: CloseMessagePipe() or PassMessagePipe() MUST be called on |runner|'s
53 // thread before this object is destroyed. 53 // thread before this object is destroyed.
54 class MultiplexRouter 54 class MultiplexRouter
55 : public MessageReceiver, 55 : public MessageReceiver,
56 public AssociatedGroupController, 56 public AssociatedGroupController,
57 public PipeControlMessageHandlerDelegate { 57 public PipeControlMessageHandlerDelegate {
58 public: 58 public:
59 enum Config {
60 // There is only the master interface running on this router. Please note
61 // that because of interface versioning, the other side of the message pipe
62 // may use a newer master interface definition which passes associated
63 // interfaces. In that case, this router may still receive pipe control
64 // messages or messages targetting associated interfaces.
65 SINGLE_INTERFACE,
66 // There may be associated interfaces running on this router.
67 MULTI_INTERFACE
68 };
69
59 // If |set_interface_id_namespace_bit| is true, the interface IDs generated by 70 // If |set_interface_id_namespace_bit| is true, the interface IDs generated by
60 // this router will have the highest bit set. 71 // this router will have the highest bit set.
61 MultiplexRouter(bool set_interface_id_namespace_bit, 72 MultiplexRouter(ScopedMessagePipeHandle message_pipe,
62 ScopedMessagePipeHandle message_pipe, 73 Config config,
74 bool set_interface_id_namespace_bit,
63 scoped_refptr<base::SingleThreadTaskRunner> runner); 75 scoped_refptr<base::SingleThreadTaskRunner> runner);
64 76
65 // Sets the master interface name for this router. Only used when reporting 77 // Sets the master interface name for this router. Only used when reporting
66 // message header or control message validation errors. 78 // message header or control message validation errors.
67 void SetMasterInterfaceName(const std::string& name); 79 void SetMasterInterfaceName(const std::string& name);
68 80
69 // --------------------------------------------------------------------------- 81 // ---------------------------------------------------------------------------
70 // The following public methods are safe to call from any threads. 82 // The following public methods are safe to call from any threads.
71 83
72 // AssociatedGroupController implementation: 84 // AssociatedGroupController implementation:
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // been closed, removes it from |endpoints_|. 210 // been closed, removes it from |endpoints_|.
199 // NOTE: The method may invalidate |endpoint|. 211 // NOTE: The method may invalidate |endpoint|.
200 enum EndpointStateUpdateType { ENDPOINT_CLOSED, PEER_ENDPOINT_CLOSED }; 212 enum EndpointStateUpdateType { ENDPOINT_CLOSED, PEER_ENDPOINT_CLOSED };
201 void UpdateEndpointStateMayRemove(InterfaceEndpoint* endpoint, 213 void UpdateEndpointStateMayRemove(InterfaceEndpoint* endpoint,
202 EndpointStateUpdateType type); 214 EndpointStateUpdateType type);
203 215
204 void RaiseErrorInNonTestingMode(); 216 void RaiseErrorInNonTestingMode();
205 217
206 InterfaceEndpoint* FindOrInsertEndpoint(InterfaceId id, bool* inserted); 218 InterfaceEndpoint* FindOrInsertEndpoint(InterfaceId id, bool* inserted);
207 219
220 void AssertLockAcquired();
221
208 // Whether to set the namespace bit when generating interface IDs. Please see 222 // Whether to set the namespace bit when generating interface IDs. Please see
209 // comments of kInterfaceIdNamespaceMask. 223 // comments of kInterfaceIdNamespaceMask.
210 const bool set_interface_id_namespace_bit_; 224 const bool set_interface_id_namespace_bit_;
211 225
212 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 226 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
213 227
214 // Owned by |filters_| below. 228 // Owned by |filters_| below.
215 MessageHeaderValidator* header_validator_; 229 MessageHeaderValidator* header_validator_;
216 230
217 FilterChain filters_; 231 FilterChain filters_;
218 Connector connector_; 232 Connector connector_;
219 233
220 base::ThreadChecker thread_checker_; 234 base::ThreadChecker thread_checker_;
221 235
222 // Protects the following members. 236 // Protects the following members.
223 mutable base::Lock lock_; 237 // Sets to nullptr in Config::SINGLE_INTERFACE mode.
238 std::unique_ptr<base::Lock> lock_;
224 PipeControlMessageHandler control_message_handler_; 239 PipeControlMessageHandler control_message_handler_;
225 PipeControlMessageProxy control_message_proxy_; 240 PipeControlMessageProxy control_message_proxy_;
226 241
227 std::map<InterfaceId, scoped_refptr<InterfaceEndpoint>> endpoints_; 242 std::map<InterfaceId, scoped_refptr<InterfaceEndpoint>> endpoints_;
228 uint32_t next_interface_id_value_; 243 uint32_t next_interface_id_value_;
229 244
230 std::deque<std::unique_ptr<Task>> tasks_; 245 std::deque<std::unique_ptr<Task>> tasks_;
231 // It refers to tasks in |tasks_| and doesn't own any of them. 246 // It refers to tasks in |tasks_| and doesn't own any of them.
232 std::map<InterfaceId, std::deque<Task*>> sync_message_tasks_; 247 std::map<InterfaceId, std::deque<Task*>> sync_message_tasks_;
233 248
234 bool posted_to_process_tasks_; 249 bool posted_to_process_tasks_;
235 scoped_refptr<base::SingleThreadTaskRunner> posted_to_task_runner_; 250 scoped_refptr<base::SingleThreadTaskRunner> posted_to_task_runner_;
236 251
237 bool encountered_error_; 252 bool encountered_error_;
238 253
239 bool paused_; 254 bool paused_;
240 255
241 bool testing_mode_; 256 bool testing_mode_;
242 257
243 DISALLOW_COPY_AND_ASSIGN(MultiplexRouter); 258 DISALLOW_COPY_AND_ASSIGN(MultiplexRouter);
244 }; 259 };
245 260
246 } // namespace internal 261 } // namespace internal
247 } // namespace mojo 262 } // namespace mojo
248 263
249 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ 264 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698