| 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 22 matching lines...) Expand all  Loading... | 
|   33 class PlatformSharedBufferMapping; |   33 class PlatformSharedBufferMapping; | 
|   34 } |   34 } | 
|   35  |   35  | 
|   36 namespace system { |   36 namespace system { | 
|   37  |   37  | 
|   38 class Awakable; |   38 class Awakable; | 
|   39 class Channel; |   39 class Channel; | 
|   40 class Core; |   40 class Core; | 
|   41 class Dispatcher; |   41 class Dispatcher; | 
|   42 class DispatcherTransport; |   42 class DispatcherTransport; | 
 |   43 struct Handle; | 
|   43 class HandleTable; |   44 class HandleTable; | 
|   44 class LocalMessagePipeEndpoint; |   45 class LocalMessagePipeEndpoint; | 
|   45 class MessagePipe; |   46 class MessagePipe; | 
|   46 class ProxyMessagePipeEndpoint; |   47 class ProxyMessagePipeEndpoint; | 
|   47 class TransportData; |   48 class TransportData; | 
|   48  |   49  | 
|   49 using DispatcherVector = std::vector<util::RefPtr<Dispatcher>>; |   50 using DispatcherVector = std::vector<util::RefPtr<Dispatcher>>; | 
|   50  |   51  | 
|   51 namespace test { |   52 namespace test { | 
|   52  |   53  | 
|   53 // Test helper. We need to declare it here so we can friend it. |   54 // Test helper. We need to declare it here so we can friend it. | 
|   54 DispatcherTransport DispatcherTryStartTransport(Dispatcher* dispatcher); |   55 DispatcherTransport HandleTryStartTransport(const Handle& handle); | 
|   55  |   56  | 
|   56 }  // namespace test |   57 }  // namespace test | 
|   57  |   58  | 
|   58 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular |   59 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular | 
|   59 // handle. This includes most (all?) primitives except for |MojoWait...()|. This |   60 // handle. This includes most (all?) primitives except for |MojoWait...()|. This | 
|   60 // object is thread-safe, with its state being protected by a single mutex |   61 // object is thread-safe, with its state being protected by a single mutex | 
|   61 // |mutex_|, which is also made available to implementation subclasses (via the |   62 // |mutex_|, which is also made available to implementation subclasses (via the | 
|   62 // |mutex()| method). |   63 // |mutex()| method). | 
|   63 class Dispatcher : public util::RefCountedThreadSafe<Dispatcher> { |   64 class Dispatcher : public util::RefCountedThreadSafe<Dispatcher> { | 
|   64  public: |   65  public: | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  195   // |  196   // | 
|  196   // In this special state, only a restricted set of operations is allowed. |  197   // In this special state, only a restricted set of operations is allowed. | 
|  197   // These are the ones available as |DispatcherTransport| methods. Other |  198   // These are the ones available as |DispatcherTransport| methods. Other | 
|  198   // |Dispatcher| methods must not be called until |DispatcherTransport::End()| |  199   // |Dispatcher| methods must not be called until |DispatcherTransport::End()| | 
|  199   // has been called. |  200   // has been called. | 
|  200   class HandleTableAccess { |  201   class HandleTableAccess { | 
|  201    private: |  202    private: | 
|  202     friend class Core; |  203     friend class Core; | 
|  203     friend class HandleTable; |  204     friend class HandleTable; | 
|  204     // Tests also need this, to avoid needing |Core|. |  205     // Tests also need this, to avoid needing |Core|. | 
|  205     friend DispatcherTransport test::DispatcherTryStartTransport(Dispatcher*); |  206     friend DispatcherTransport test::HandleTryStartTransport(const Handle&); | 
|  206  |  207  | 
|  207     // This must be called under the handle table lock and only if the handle |  208     // This must be called under the handle table lock and only if the handle | 
|  208     // table entry is not marked busy. The caller must maintain a reference to |  209     // table entry is not marked busy. The caller must maintain a reference to | 
|  209     // |dispatcher| until |DispatcherTransport::End()| is called. |  210     // |dispatcher| until |DispatcherTransport::End()| is called. | 
|  210     static DispatcherTransport TryStartTransport(Dispatcher* dispatcher); |  211     static DispatcherTransport TryStartTransport(const Handle& handle); | 
|  211   }; |  212   }; | 
|  212  |  213  | 
|  213   // A |TransportData| may serialize dispatchers that are given to it (and which |  214   // A |TransportData| may serialize dispatchers that are given to it (and which | 
|  214   // were previously attached to the |MessageInTransit| that is creating it) to |  215   // were previously attached to the |MessageInTransit| that is creating it) to | 
|  215   // a given |Channel| and then (probably in a different process) deserialize. |  216   // a given |Channel| and then (probably in a different process) deserialize. | 
|  216   // Note that the |MessageInTransit| "owns" (i.e., has the only ref to) these |  217   // Note that the |MessageInTransit| "owns" (i.e., has the only ref to) these | 
|  217   // dispatchers, so there are no locking issues. (There's no lock ordering |  218   // dispatchers, so there are no locking issues. (There's no lock ordering | 
|  218   // issue, and in fact no need to take dispatcher locks at all.) |  219   // issue, and in fact no need to take dispatcher locks at all.) | 
|  219   // TODO(vtl): Consider making another wrapper similar to |DispatcherTransport| |  220   // TODO(vtl): Consider making another wrapper similar to |DispatcherTransport| | 
|  220   // (but with an owning, unique reference), and having |  221   // (but with an owning, unique reference), and having | 
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  446  |  447  | 
|  447 // So logging macros and |DCHECK_EQ()|, etc. work. |  448 // So logging macros and |DCHECK_EQ()|, etc. work. | 
|  448 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { |  449 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { | 
|  449   return out << static_cast<int>(type); |  450   return out << static_cast<int>(type); | 
|  450 } |  451 } | 
|  451  |  452  | 
|  452 }  // namespace system |  453 }  // namespace system | 
|  453 }  // namespace mojo |  454 }  // namespace mojo | 
|  454  |  455  | 
|  455 #endif  // MOJO_EDK_SYSTEM_DISPATCHER_H_ |  456 #endif  // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 
| OLD | NEW |