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_DATA_PIPE_H_ | 5 #ifndef MOJO_SYSTEM_DATA_PIPE_H_ |
6 #define MOJO_SYSTEM_DATA_PIPE_H_ | 6 #define MOJO_SYSTEM_DATA_PIPE_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/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.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/types.h" | 15 #include "mojo/public/c/system/types.h" |
| 16 #include "mojo/system/handle_signals_state.h" |
16 #include "mojo/system/system_impl_export.h" | 17 #include "mojo/system/system_impl_export.h" |
17 #include "mojo/system/wait_flags_state.h" | |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace system { | 20 namespace system { |
21 | 21 |
22 class Waiter; | 22 class Waiter; |
23 class WaiterList; | 23 class WaiterList; |
24 | 24 |
25 // |DataPipe| is a base class for secondary objects implementing data pipes, | 25 // |DataPipe| is a base class for secondary objects implementing data pipes, |
26 // similar to |MessagePipe| (see the explanatory comment in core.cc). It is | 26 // similar to |MessagePipe| (see the explanatory comment in core.cc). It is |
27 // typically owned by the dispatcher(s) corresponding to the local endpoints. | 27 // typically owned by the dispatcher(s) corresponding to the local endpoints. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 virtual MojoResult ProducerWriteDataImplNoLock(const void* elements, | 101 virtual MojoResult ProducerWriteDataImplNoLock(const void* elements, |
102 uint32_t* num_bytes, | 102 uint32_t* num_bytes, |
103 bool all_or_none) = 0; | 103 bool all_or_none) = 0; |
104 virtual MojoResult ProducerBeginWriteDataImplNoLock( | 104 virtual MojoResult ProducerBeginWriteDataImplNoLock( |
105 void** buffer, | 105 void** buffer, |
106 uint32_t* buffer_num_bytes, | 106 uint32_t* buffer_num_bytes, |
107 bool all_or_none) = 0; | 107 bool all_or_none) = 0; |
108 virtual MojoResult ProducerEndWriteDataImplNoLock( | 108 virtual MojoResult ProducerEndWriteDataImplNoLock( |
109 uint32_t num_bytes_written) = 0; | 109 uint32_t num_bytes_written) = 0; |
110 // Note: A producer should not be writable during a two-phase write. | 110 // Note: A producer should not be writable during a two-phase write. |
111 virtual WaitFlagsState ProducerGetWaitFlagsStateNoLock() const = 0; | 111 virtual HandleSignalsState ProducerGetHandleSignalsStateNoLock() const = 0; |
112 | 112 |
113 virtual void ConsumerCloseImplNoLock() = 0; | 113 virtual void ConsumerCloseImplNoLock() = 0; |
114 // |*num_bytes| will be a nonzero multiple of |element_num_bytes_|. | 114 // |*num_bytes| will be a nonzero multiple of |element_num_bytes_|. |
115 virtual MojoResult ConsumerReadDataImplNoLock(void* elements, | 115 virtual MojoResult ConsumerReadDataImplNoLock(void* elements, |
116 uint32_t* num_bytes, | 116 uint32_t* num_bytes, |
117 bool all_or_none) = 0; | 117 bool all_or_none) = 0; |
118 virtual MojoResult ConsumerDiscardDataImplNoLock(uint32_t* num_bytes, | 118 virtual MojoResult ConsumerDiscardDataImplNoLock(uint32_t* num_bytes, |
119 bool all_or_none) = 0; | 119 bool all_or_none) = 0; |
120 // |*num_bytes| will be a nonzero multiple of |element_num_bytes_|. | 120 // |*num_bytes| will be a nonzero multiple of |element_num_bytes_|. |
121 virtual MojoResult ConsumerQueryDataImplNoLock(uint32_t* num_bytes) = 0; | 121 virtual MojoResult ConsumerQueryDataImplNoLock(uint32_t* num_bytes) = 0; |
122 virtual MojoResult ConsumerBeginReadDataImplNoLock(const void** buffer, | 122 virtual MojoResult ConsumerBeginReadDataImplNoLock(const void** buffer, |
123 uint32_t* buffer_num_bytes, | 123 uint32_t* buffer_num_bytes, |
124 bool all_or_none) = 0; | 124 bool all_or_none) = 0; |
125 virtual MojoResult ConsumerEndReadDataImplNoLock(uint32_t num_bytes_read) = 0; | 125 virtual MojoResult ConsumerEndReadDataImplNoLock(uint32_t num_bytes_read) = 0; |
126 // Note: A consumer should not be writable during a two-phase read. | 126 // Note: A consumer should not be writable during a two-phase read. |
127 virtual WaitFlagsState ConsumerGetWaitFlagsStateNoLock() const = 0; | 127 virtual HandleSignalsState ConsumerGetHandleSignalsStateNoLock() const = 0; |
128 | 128 |
129 // Thread-safe and fast (they don't take the lock): | 129 // Thread-safe and fast (they don't take the lock): |
130 bool may_discard() const { return may_discard_; } | 130 bool may_discard() const { return may_discard_; } |
131 size_t element_num_bytes() const { return element_num_bytes_; } | 131 size_t element_num_bytes() const { return element_num_bytes_; } |
132 size_t capacity_num_bytes() const { return capacity_num_bytes_; } | 132 size_t capacity_num_bytes() const { return capacity_num_bytes_; } |
133 | 133 |
134 // Must be called under lock. | 134 // Must be called under lock. |
135 bool producer_open_no_lock() const { | 135 bool producer_open_no_lock() const { |
136 lock_.AssertAcquired(); | 136 lock_.AssertAcquired(); |
137 return producer_open_; | 137 return producer_open_; |
(...skipping 23 matching lines...) Expand all Loading... |
161 lock_.AssertAcquired(); | 161 lock_.AssertAcquired(); |
162 return producer_two_phase_max_num_bytes_written_ > 0; | 162 return producer_two_phase_max_num_bytes_written_ > 0; |
163 } | 163 } |
164 bool consumer_in_two_phase_read_no_lock() const { | 164 bool consumer_in_two_phase_read_no_lock() const { |
165 lock_.AssertAcquired(); | 165 lock_.AssertAcquired(); |
166 return consumer_two_phase_max_num_bytes_read_ > 0; | 166 return consumer_two_phase_max_num_bytes_read_ > 0; |
167 } | 167 } |
168 | 168 |
169 private: | 169 private: |
170 void AwakeProducerWaitersForStateChangeNoLock( | 170 void AwakeProducerWaitersForStateChangeNoLock( |
171 const WaitFlagsState& new_producer_state); | 171 const HandleSignalsState& new_producer_state); |
172 void AwakeConsumerWaitersForStateChangeNoLock( | 172 void AwakeConsumerWaitersForStateChangeNoLock( |
173 const WaitFlagsState& new_consumer_state); | 173 const HandleSignalsState& new_consumer_state); |
174 | 174 |
175 bool has_local_producer_no_lock() const { | 175 bool has_local_producer_no_lock() const { |
176 lock_.AssertAcquired(); | 176 lock_.AssertAcquired(); |
177 return !!producer_waiter_list_; | 177 return !!producer_waiter_list_; |
178 } | 178 } |
179 bool has_local_consumer_no_lock() const { | 179 bool has_local_consumer_no_lock() const { |
180 lock_.AssertAcquired(); | 180 lock_.AssertAcquired(); |
181 return !!consumer_waiter_list_; | 181 return !!consumer_waiter_list_; |
182 } | 182 } |
183 | 183 |
(...skipping 12 matching lines...) Expand all Loading... |
196 uint32_t producer_two_phase_max_num_bytes_written_; | 196 uint32_t producer_two_phase_max_num_bytes_written_; |
197 uint32_t consumer_two_phase_max_num_bytes_read_; | 197 uint32_t consumer_two_phase_max_num_bytes_read_; |
198 | 198 |
199 DISALLOW_COPY_AND_ASSIGN(DataPipe); | 199 DISALLOW_COPY_AND_ASSIGN(DataPipe); |
200 }; | 200 }; |
201 | 201 |
202 } // namespace system | 202 } // namespace system |
203 } // namespace mojo | 203 } // namespace mojo |
204 | 204 |
205 #endif // MOJO_SYSTEM_DATA_PIPE_H_ | 205 #endif // MOJO_SYSTEM_DATA_PIPE_H_ |
OLD | NEW |