OLD | NEW |
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_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DISPATCHER_H_ |
6 #define MOJO_EDK_SYSTEM_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_DISPATCHER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 virtual bool SupportsEntrypointClass( | 91 virtual bool SupportsEntrypointClass( |
92 EntrypointClass entrypoint_class) const = 0; | 92 EntrypointClass entrypoint_class) const = 0; |
93 | 93 |
94 // These methods implement the various primitives named |Mojo...()|. These | 94 // These methods implement the various primitives named |Mojo...()|. These |
95 // take |mutex_| and handle races with |Close()|. Then they call out to | 95 // take |mutex_| and handle races with |Close()|. Then they call out to |
96 // subclasses' |...ImplNoLock()| methods (still under |mutex_|), which | 96 // subclasses' |...ImplNoLock()| methods (still under |mutex_|), which |
97 // actually implement the primitives. | 97 // actually implement the primitives. |
98 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and | 98 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and |
99 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as | 99 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as |
100 // possible. If this becomes an issue, we can rethink this. | 100 // possible. If this becomes an issue, we can rethink this. |
| 101 |
| 102 // No |EntrypointClass|: |
| 103 // All dispatchers must support this. |
101 MojoResult Close(); | 104 MojoResult Close(); |
| 105 // This actually supports |MojoDuplicateHandle[WithReducedRights]()|; rights |
| 106 // are handled by |Core|. |
| 107 MojoResult DuplicateDispatcher(util::RefPtr<Dispatcher>* new_dispatcher); |
102 | 108 |
103 // |EntrypointClass::MESSAGE_PIPE|: | 109 // |EntrypointClass::MESSAGE_PIPE|: |
104 // |transports| may be non-null if and only if there are handles to be | 110 // |transports| may be non-null if and only if there are handles to be |
105 // written; not that |this| must not be in |transports|. On success, all the | 111 // written; not that |this| must not be in |transports|. On success, all the |
106 // dispatchers in |transports| must have been moved to a closed state; on | 112 // dispatchers in |transports| must have been moved to a closed state; on |
107 // failure, they should remain in their original state. | 113 // failure, they should remain in their original state. |
108 MojoResult WriteMessage(UserPointer<const void> bytes, | 114 MojoResult WriteMessage(UserPointer<const void> bytes, |
109 uint32_t num_bytes, | 115 uint32_t num_bytes, |
110 std::vector<HandleTransport>* transports, | 116 std::vector<HandleTransport>* transports, |
111 MojoWriteMessageFlags flags); | 117 MojoWriteMessageFlags flags); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 protected: | 261 protected: |
256 Dispatcher(); | 262 Dispatcher(); |
257 virtual ~Dispatcher(); | 263 virtual ~Dispatcher(); |
258 | 264 |
259 // These are to be overridden by subclasses (if necessary). They are called | 265 // These are to be overridden by subclasses (if necessary). They are called |
260 // exactly once (first |CancelAllAwakablesNoLock()|, then |CloseImplNoLock()|) | 266 // exactly once (first |CancelAllAwakablesNoLock()|, then |CloseImplNoLock()|) |
261 // when the dispatcher is being closed. | 267 // when the dispatcher is being closed. |
262 virtual void CancelAllAwakablesNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 268 virtual void CancelAllAwakablesNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
263 virtual void CloseImplNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 269 virtual void CloseImplNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
264 | 270 |
| 271 // All dispatcher types whose handles may ever have the |
| 272 // |MOJO_HANDLE_RIGHT_DUPLICATE| right must override this. |
| 273 virtual MojoResult DuplicateDispatcherImplNoLock( |
| 274 util::RefPtr<Dispatcher>* new_dispatcher) |
| 275 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
| 276 |
265 // This is called by |CreateEquivalentDispatcherAndCloseNoLock()|. It should | 277 // This is called by |CreateEquivalentDispatcherAndCloseNoLock()|. It should |
266 // "close" this dispatcher and return a new one equivalent to it. Note: | 278 // "close" this dispatcher and return a new one equivalent to it. Note: |
267 // Probably the first thing an implementation should do is call | 279 // Probably the first thing an implementation should do is call |
268 // |CancelAllAwakablesNoLock()| (or equivalent); unlike |CloseNoLock()|, | 280 // |CancelAllAwakablesNoLock()| (or equivalent); unlike |CloseNoLock()|, |
269 // |CreateEquivalentDispatcherAndCloseNoLock()| does not do this | 281 // |CreateEquivalentDispatcherAndCloseNoLock()| does not do this |
270 // automatically. | 282 // automatically. |
271 virtual util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock( | 283 virtual util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock( |
272 MessagePipe* message_pipe, | 284 MessagePipe* message_pipe, |
273 unsigned port) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_) = 0; | 285 unsigned port) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_) = 0; |
274 | 286 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 459 |
448 // So logging macros and |DCHECK_EQ()|, etc. work. | 460 // So logging macros and |DCHECK_EQ()|, etc. work. |
449 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { | 461 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { |
450 return out << static_cast<int>(type); | 462 return out << static_cast<int>(type); |
451 } | 463 } |
452 | 464 |
453 } // namespace system | 465 } // namespace system |
454 } // namespace mojo | 466 } // namespace mojo |
455 | 467 |
456 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 468 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
OLD | NEW |