| 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_SYSTEM_CORE_H_ | 5 #ifndef MOJO_SYSTEM_CORE_H_ |
| 6 #define MOJO_SYSTEM_CORE_H_ | 6 #define MOJO_SYSTEM_CORE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "mojo/public/c/system/buffer.h" | 13 #include "mojo/public/c/system/buffer.h" |
| 14 #include "mojo/public/c/system/data_pipe.h" | 14 #include "mojo/public/c/system/data_pipe.h" |
| 15 #include "mojo/public/c/system/message_pipe.h" | 15 #include "mojo/public/c/system/message_pipe.h" |
| 16 #include "mojo/public/c/system/types.h" | 16 #include "mojo/public/c/system/types.h" |
| 17 #include "mojo/system/handle_table.h" | 17 #include "mojo/system/handle_table.h" |
| 18 #include "mojo/system/mapping_table.h" | 18 #include "mojo/system/mapping_table.h" |
| 19 #include "mojo/system/memory.h" | 19 #include "mojo/system/memory.h" |
| 20 #include "mojo/system/system_impl_export.h" | 20 #include "mojo/system/system_impl_export.h" |
| 21 | 21 |
| 22 namespace mojo { | 22 namespace mojo { |
| 23 namespace system { | 23 namespace system { |
| 24 | 24 |
| 25 class Dispatcher; | 25 class Dispatcher; |
| 26 struct HandleSignalsState; |
| 26 | 27 |
| 27 // |Core| is an object that implements the Mojo system calls. All public methods | 28 // |Core| is an object that implements the Mojo system calls. All public methods |
| 28 // are thread-safe. | 29 // are thread-safe. |
| 29 class MOJO_SYSTEM_IMPL_EXPORT Core { | 30 class MOJO_SYSTEM_IMPL_EXPORT Core { |
| 30 public: | 31 public: |
| 31 // These methods are only to be used by via the embedder API (and internally). | 32 // These methods are only to be used by via the embedder API (and internally). |
| 32 Core(); | 33 Core(); |
| 33 virtual ~Core(); | 34 virtual ~Core(); |
| 34 | 35 |
| 35 // Adds |dispatcher| to the handle table, returning the handle for it. Returns | 36 // Adds |dispatcher| to the handle table, returning the handle for it. Returns |
| 36 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full. | 37 // |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full. |
| 37 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); | 38 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); |
| 38 | 39 |
| 39 // Looks up the dispatcher for the given handle. Returns null if the handle is | 40 // Looks up the dispatcher for the given handle. Returns null if the handle is |
| 40 // invalid. | 41 // invalid. |
| 41 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); | 42 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); |
| 42 | 43 |
| 43 // System calls implementation. | 44 // System calls implementation. |
| 44 MojoTimeTicks GetTimeTicksNow(); | 45 MojoTimeTicks GetTimeTicksNow(); |
| 45 MojoResult Close(MojoHandle handle); | 46 MojoResult Close(MojoHandle handle); |
| 46 MojoResult Wait(MojoHandle handle, | 47 MojoResult Wait(MojoHandle handle, |
| 47 MojoHandleSignals signals, | 48 MojoHandleSignals signals, |
| 48 MojoDeadline deadline); | 49 MojoDeadline deadline, |
| 50 UserPointer<MojoHandleSignalsState> signals_state); |
| 49 MojoResult WaitMany(UserPointer<const MojoHandle> handles, | 51 MojoResult WaitMany(UserPointer<const MojoHandle> handles, |
| 50 UserPointer<const MojoHandleSignals> signals, | 52 UserPointer<const MojoHandleSignals> signals, |
| 51 uint32_t num_handles, | 53 uint32_t num_handles, |
| 52 MojoDeadline deadline); | 54 MojoDeadline deadline, |
| 55 UserPointer<uint32_t> result_index, |
| 56 UserPointer<MojoHandleSignalsState> signals_states); |
| 53 MojoResult CreateMessagePipe( | 57 MojoResult CreateMessagePipe( |
| 54 UserPointer<const MojoCreateMessagePipeOptions> options, | 58 UserPointer<const MojoCreateMessagePipeOptions> options, |
| 55 UserPointer<MojoHandle> message_pipe_handle0, | 59 UserPointer<MojoHandle> message_pipe_handle0, |
| 56 UserPointer<MojoHandle> message_pipe_handle1); | 60 UserPointer<MojoHandle> message_pipe_handle1); |
| 57 MojoResult WriteMessage(MojoHandle message_pipe_handle, | 61 MojoResult WriteMessage(MojoHandle message_pipe_handle, |
| 58 UserPointer<const void> bytes, | 62 UserPointer<const void> bytes, |
| 59 uint32_t num_bytes, | 63 uint32_t num_bytes, |
| 60 UserPointer<const MojoHandle> handles, | 64 UserPointer<const MojoHandle> handles, |
| 61 uint32_t num_handles, | 65 uint32_t num_handles, |
| 62 MojoWriteMessageFlags flags); | 66 MojoWriteMessageFlags flags); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 friend bool internal::ShutdownCheckNoLeaks(Core*); | 113 friend bool internal::ShutdownCheckNoLeaks(Core*); |
| 110 | 114 |
| 111 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic | 115 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic |
| 112 // validation of arguments. |*result_index| is only set if the result (whether | 116 // validation of arguments. |*result_index| is only set if the result (whether |
| 113 // success or failure) applies to a specific handle, so its value should be | 117 // success or failure) applies to a specific handle, so its value should be |
| 114 // preinitialized to |static_cast<uint32_t>(-1)|. | 118 // preinitialized to |static_cast<uint32_t>(-1)|. |
| 115 MojoResult WaitManyInternal(const MojoHandle* handles, | 119 MojoResult WaitManyInternal(const MojoHandle* handles, |
| 116 const MojoHandleSignals* signals, | 120 const MojoHandleSignals* signals, |
| 117 uint32_t num_handles, | 121 uint32_t num_handles, |
| 118 MojoDeadline deadline, | 122 MojoDeadline deadline, |
| 119 uint32_t* result_index); | 123 uint32_t* result_index, |
| 124 HandleSignalsState* signals_states); |
| 120 | 125 |
| 121 // --------------------------------------------------------------------------- | 126 // --------------------------------------------------------------------------- |
| 122 | 127 |
| 123 // TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we | 128 // TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we |
| 124 // had them). | 129 // had them). |
| 125 base::Lock handle_table_lock_; // Protects |handle_table_|. | 130 base::Lock handle_table_lock_; // Protects |handle_table_|. |
| 126 HandleTable handle_table_; | 131 HandleTable handle_table_; |
| 127 | 132 |
| 128 base::Lock mapping_table_lock_; // Protects |mapping_table_|. | 133 base::Lock mapping_table_lock_; // Protects |mapping_table_|. |
| 129 MappingTable mapping_table_; | 134 MappingTable mapping_table_; |
| 130 | 135 |
| 131 // --------------------------------------------------------------------------- | 136 // --------------------------------------------------------------------------- |
| 132 | 137 |
| 133 DISALLOW_COPY_AND_ASSIGN(Core); | 138 DISALLOW_COPY_AND_ASSIGN(Core); |
| 134 }; | 139 }; |
| 135 | 140 |
| 136 } // namespace system | 141 } // namespace system |
| 137 } // namespace mojo | 142 } // namespace mojo |
| 138 | 143 |
| 139 #endif // MOJO_SYSTEM_CORE_H_ | 144 #endif // MOJO_SYSTEM_CORE_H_ |
| OLD | NEW |