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 |
| 11 #include <ostream> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
17 #include "mojo/edk/embedder/platform_handle_vector.h" | 18 #include "mojo/edk/embedder/platform_handle_vector.h" |
18 #include "mojo/edk/system/handle_signals_state.h" | 19 #include "mojo/edk/system/handle_signals_state.h" |
19 #include "mojo/edk/system/memory.h" | 20 #include "mojo/edk/system/memory.h" |
20 #include "mojo/edk/system/system_impl_export.h" | 21 #include "mojo/edk/system/system_impl_export.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } // namespace test | 53 } // namespace test |
53 | 54 |
54 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular | 55 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular |
55 // handle. This includes most (all?) primitives except for |MojoWait...()|. This | 56 // handle. This includes most (all?) primitives except for |MojoWait...()|. This |
56 // object is thread-safe, with its state being protected by a single lock | 57 // object is thread-safe, with its state being protected by a single lock |
57 // |lock_|, which is also made available to implementation subclasses (via the | 58 // |lock_|, which is also made available to implementation subclasses (via the |
58 // |lock()| method). | 59 // |lock()| method). |
59 class MOJO_SYSTEM_IMPL_EXPORT Dispatcher | 60 class MOJO_SYSTEM_IMPL_EXPORT Dispatcher |
60 : public base::RefCountedThreadSafe<Dispatcher> { | 61 : public base::RefCountedThreadSafe<Dispatcher> { |
61 public: | 62 public: |
62 enum Type { | 63 enum class Type { |
63 kTypeUnknown = 0, | 64 UNKNOWN = 0, |
64 kTypeMessagePipe, | 65 MESSAGE_PIPE, |
65 kTypeDataPipeProducer, | 66 DATA_PIPE_PRODUCER, |
66 kTypeDataPipeConsumer, | 67 DATA_PIPE_CONSUMER, |
67 kTypeSharedBuffer, | 68 SHARED_BUFFER, |
68 | 69 |
69 // "Private" types (not exposed via the public interface): | 70 // "Private" types (not exposed via the public interface): |
70 kTypePlatformHandle = -1 | 71 PLATFORM_HANDLE = -1 |
71 }; | 72 }; |
72 virtual Type GetType() const = 0; | 73 virtual Type GetType() const = 0; |
73 | 74 |
74 // These methods implement the various primitives named |Mojo...()|. These | 75 // These methods implement the various primitives named |Mojo...()|. These |
75 // take |lock_| and handle races with |Close()|. Then they call out to | 76 // take |lock_| and handle races with |Close()|. Then they call out to |
76 // subclasses' |...ImplNoLock()| methods (still under |lock_|), which actually | 77 // subclasses' |...ImplNoLock()| methods (still under |lock_|), which actually |
77 // implement the primitives. | 78 // implement the primitives. |
78 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and | 79 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and |
79 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as | 80 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as |
80 // possible. If this becomes an issue, we can rethink this. | 81 // possible. If this becomes an issue, we can rethink this. |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 friend class Dispatcher::HandleTableAccess; | 393 friend class Dispatcher::HandleTableAccess; |
393 | 394 |
394 explicit DispatcherTransport(Dispatcher* dispatcher) | 395 explicit DispatcherTransport(Dispatcher* dispatcher) |
395 : dispatcher_(dispatcher) {} | 396 : dispatcher_(dispatcher) {} |
396 | 397 |
397 Dispatcher* dispatcher_; | 398 Dispatcher* dispatcher_; |
398 | 399 |
399 // Copy and assign allowed. | 400 // Copy and assign allowed. |
400 }; | 401 }; |
401 | 402 |
| 403 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 404 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, |
| 405 Dispatcher::Type type) { |
| 406 return out << static_cast<int>(type); |
| 407 } |
| 408 |
402 } // namespace system | 409 } // namespace system |
403 } // namespace mojo | 410 } // namespace mojo |
404 | 411 |
405 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 412 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
OLD | NEW |