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 17 matching lines...) Expand all Loading... | |
28 #include "mojo/public/cpp/system/macros.h" | 28 #include "mojo/public/cpp/system/macros.h" |
29 | 29 |
30 namespace mojo { | 30 namespace mojo { |
31 | 31 |
32 namespace platform { | 32 namespace platform { |
33 class PlatformSharedBufferMapping; | 33 class PlatformSharedBufferMapping; |
34 } | 34 } |
35 | 35 |
36 namespace system { | 36 namespace system { |
37 | 37 |
38 class Awakable; | |
38 class Channel; | 39 class Channel; |
39 class Core; | 40 class Core; |
40 class Dispatcher; | 41 class Dispatcher; |
41 class DispatcherTransport; | 42 class DispatcherTransport; |
42 class HandleTable; | 43 class HandleTable; |
43 class LocalMessagePipeEndpoint; | 44 class LocalMessagePipeEndpoint; |
45 class MessagePipe; | |
44 class ProxyMessagePipeEndpoint; | 46 class ProxyMessagePipeEndpoint; |
45 class TransportData; | 47 class TransportData; |
46 class Awakable; | |
47 | 48 |
48 using DispatcherVector = std::vector<util::RefPtr<Dispatcher>>; | 49 using DispatcherVector = std::vector<util::RefPtr<Dispatcher>>; |
49 | 50 |
50 namespace test { | 51 namespace test { |
51 | 52 |
52 // Test helper. We need to declare it here so we can friend it. | 53 // Test helper. We need to declare it here so we can friend it. |
53 DispatcherTransport DispatcherTryStartTransport(Dispatcher* dispatcher); | 54 DispatcherTransport DispatcherTryStartTransport(Dispatcher* dispatcher); |
54 | 55 |
55 } // namespace test | 56 } // namespace test |
56 | 57 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 protected: | 253 protected: |
253 Dispatcher(); | 254 Dispatcher(); |
254 virtual ~Dispatcher(); | 255 virtual ~Dispatcher(); |
255 | 256 |
256 // These are to be overridden by subclasses (if necessary). They are called | 257 // These are to be overridden by subclasses (if necessary). They are called |
257 // exactly once (first |CancelAllAwakablesNoLock()|, then |CloseImplNoLock()|) | 258 // exactly once (first |CancelAllAwakablesNoLock()|, then |CloseImplNoLock()|) |
258 // when the dispatcher is being closed. | 259 // when the dispatcher is being closed. |
259 virtual void CancelAllAwakablesNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 260 virtual void CancelAllAwakablesNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
260 virtual void CloseImplNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 261 virtual void CloseImplNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
261 | 262 |
262 virtual util::RefPtr<Dispatcher> | 263 // This is called by |CreateEquivalentDispatcherAndCloseNoLock()|. It should |
263 CreateEquivalentDispatcherAndCloseImplNoLock() | 264 // produce "close" this dispatcher and return a new one equivalent to it. |
azani
2016/05/03 19:54:27
The meaning of "produce 'close' this dispatcher" i
viettrungluu
2016/05/03 20:28:01
Oops, I meant to s/produce // this before landing.
| |
264 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_) = 0; | 265 // Note: Probably the first thing an implementation should do is call |
266 // |CancelAllAwakablesNoLock()| (or equivalent); unlike |CloseNoLock()|, | |
267 // |CreateEquivalentDispatcherAndCloseNoLock()| does not do this | |
268 // automatically. | |
269 virtual util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock( | |
270 MessagePipe* message_pipe, | |
271 unsigned port) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_) = 0; | |
265 | 272 |
266 // These are to be overridden by subclasses (if necessary). They are never | 273 // These are to be overridden by subclasses (if necessary). They are never |
267 // called after the dispatcher has been closed. See the descriptions of the | 274 // called after the dispatcher has been closed. See the descriptions of the |
268 // methods without the "ImplNoLock" for more information. | 275 // methods without the "ImplNoLock" for more information. |
269 virtual MojoResult WriteMessageImplNoLock( | 276 virtual MojoResult WriteMessageImplNoLock( |
270 UserPointer<const void> bytes, | 277 UserPointer<const void> bytes, |
271 uint32_t num_bytes, | 278 uint32_t num_bytes, |
272 std::vector<DispatcherTransport>* transports, | 279 std::vector<DispatcherTransport>* transports, |
273 MojoWriteMessageFlags flags) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 280 MojoWriteMessageFlags flags) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
274 virtual MojoResult ReadMessageImplNoLock(UserPointer<void> bytes, | 281 virtual MojoResult ReadMessageImplNoLock(UserPointer<void> bytes, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 // Closes the dispatcher. This must be done under lock, and unlike |Close()|, | 379 // Closes the dispatcher. This must be done under lock, and unlike |Close()|, |
373 // the dispatcher must not be closed already. (This is the "equivalent" of | 380 // the dispatcher must not be closed already. (This is the "equivalent" of |
374 // |CreateEquivalentDispatcherAndCloseNoLock()|, for situations where the | 381 // |CreateEquivalentDispatcherAndCloseNoLock()|, for situations where the |
375 // dispatcher must be disposed of instead of "transferred".) | 382 // dispatcher must be disposed of instead of "transferred".) |
376 void CloseNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 383 void CloseNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
377 | 384 |
378 // Creates an equivalent dispatcher -- representing the same resource as this | 385 // Creates an equivalent dispatcher -- representing the same resource as this |
379 // dispatcher -- and close (i.e., disable) this dispatcher. I.e., this | 386 // dispatcher -- and close (i.e., disable) this dispatcher. I.e., this |
380 // dispatcher will look as though it was closed, but the resource it | 387 // dispatcher will look as though it was closed, but the resource it |
381 // represents will be assigned to the new dispatcher. This must be called | 388 // represents will be assigned to the new dispatcher. This must be called |
382 // under the dispatcher's lock. | 389 // under the dispatcher's lock. If the resulting dispatcher will be put into a |
383 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseNoLock() | 390 // message on a message pipe, then |message_pipe| will be set appropriately |
384 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 391 // (otherwise, it may be null) and |port| will be set to the destination port. |
392 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseNoLock( | |
393 MessagePipe* message_pipe, | |
394 unsigned port) MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | |
385 | 395 |
386 // API to serialize dispatchers to a |Channel|, exposed to only | 396 // API to serialize dispatchers to a |Channel|, exposed to only |
387 // |TransportData| (via |TransportData|). They may only be called on a | 397 // |TransportData| (via |TransportData|). They may only be called on a |
388 // dispatcher attached to a |MessageInTransit| (and in particular not in | 398 // dispatcher attached to a |MessageInTransit| (and in particular not in |
389 // |CoreImpl|'s handle table). | 399 // |CoreImpl|'s handle table). |
390 // | 400 // |
391 // TODO(vtl): The serialization API (and related implementation methods, | 401 // TODO(vtl): The serialization API (and related implementation methods, |
392 // including |DispatcherTransport|'s methods) is marked | 402 // including |DispatcherTransport|'s methods) is marked |
393 // |MOJO_NOT_THREAD_SAFE|. This is because the threading requirements are | 403 // |MOJO_NOT_THREAD_SAFE|. This is because the threading requirements are |
394 // somewhat complicated (e.g., |HandleTableAccess::TryStartTransport()| is | 404 // somewhat complicated (e.g., |HandleTableAccess::TryStartTransport()| is |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 | 443 |
434 MOJO_DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 444 MOJO_DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
435 }; | 445 }; |
436 | 446 |
437 // Wrapper around a |Dispatcher| pointer, while it's being processed to be | 447 // Wrapper around a |Dispatcher| pointer, while it's being processed to be |
438 // passed in a message pipe. See the comment about | 448 // passed in a message pipe. See the comment about |
439 // |Dispatcher::HandleTableAccess| for more details. | 449 // |Dispatcher::HandleTableAccess| for more details. |
440 // | 450 // |
441 // Note: This class is deliberately "thin" -- no more expensive than a | 451 // Note: This class is deliberately "thin" -- no more expensive than a |
442 // |Dispatcher*|. | 452 // |Dispatcher*|. |
443 class DispatcherTransport { | 453 class DispatcherTransport final { |
444 public: | 454 public: |
445 DispatcherTransport() : dispatcher_(nullptr) {} | 455 DispatcherTransport() : dispatcher_(nullptr) {} |
446 | 456 |
447 void End() MOJO_NOT_THREAD_SAFE; | 457 void End() MOJO_NOT_THREAD_SAFE; |
448 | 458 |
449 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } | 459 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } |
450 bool IsBusy() const MOJO_NOT_THREAD_SAFE { | 460 bool IsBusy() const MOJO_NOT_THREAD_SAFE { |
451 return dispatcher_->IsBusyNoLock(); | 461 return dispatcher_->IsBusyNoLock(); |
452 } | 462 } |
453 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } | 463 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } |
454 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndClose() | 464 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndClose( |
455 MOJO_NOT_THREAD_SAFE { | 465 MessagePipe* message_pipe, |
456 return dispatcher_->CreateEquivalentDispatcherAndCloseNoLock(); | 466 unsigned port) MOJO_NOT_THREAD_SAFE { |
467 return dispatcher_->CreateEquivalentDispatcherAndCloseNoLock(message_pipe, | |
468 port); | |
457 } | 469 } |
458 | 470 |
459 bool is_valid() const { return !!dispatcher_; } | 471 bool is_valid() const { return !!dispatcher_; } |
460 | 472 |
461 protected: | |
462 Dispatcher* dispatcher() { return dispatcher_; } | |
463 | |
464 private: | 473 private: |
465 friend class Dispatcher::HandleTableAccess; | 474 friend class Dispatcher::HandleTableAccess; |
466 | 475 |
467 explicit DispatcherTransport(Dispatcher* dispatcher) | 476 explicit DispatcherTransport(Dispatcher* dispatcher) |
468 : dispatcher_(dispatcher) {} | 477 : dispatcher_(dispatcher) {} |
469 | 478 |
470 Dispatcher* dispatcher_; | 479 Dispatcher* dispatcher_; |
471 | 480 |
472 // Copy and assign allowed. | 481 // Copy and assign allowed. |
473 }; | 482 }; |
474 | 483 |
475 // So logging macros and |DCHECK_EQ()|, etc. work. | 484 // So logging macros and |DCHECK_EQ()|, etc. work. |
476 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { | 485 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { |
477 return out << static_cast<int>(type); | 486 return out << static_cast<int>(type); |
478 } | 487 } |
479 | 488 |
480 } // namespace system | 489 } // namespace system |
481 } // namespace mojo | 490 } // namespace mojo |
482 | 491 |
483 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 492 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
OLD | NEW |