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_DATA_PIPE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_H_ |
6 #define MOJO_EDK_SYSTEM_DATA_PIPE_H_ | 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "mojo/edk/embedder/platform_handle_vector.h" | 13 #include "mojo/edk/embedder/platform_handle_vector.h" |
15 #include "mojo/edk/system/channel_endpoint_client.h" | 14 #include "mojo/edk/system/channel_endpoint_client.h" |
16 #include "mojo/edk/system/handle_signals_state.h" | 15 #include "mojo/edk/system/handle_signals_state.h" |
17 #include "mojo/edk/system/memory.h" | 16 #include "mojo/edk/system/memory.h" |
18 #include "mojo/edk/system/mutex.h" | 17 #include "mojo/edk/system/mutex.h" |
19 #include "mojo/edk/system/system_impl_export.h" | 18 #include "mojo/edk/system/system_impl_export.h" |
20 #include "mojo/edk/system/thread_annotations.h" | 19 #include "mojo/edk/system/thread_annotations.h" |
21 #include "mojo/public/c/system/data_pipe.h" | 20 #include "mojo/public/c/system/data_pipe.h" |
22 #include "mojo/public/c/system/types.h" | 21 #include "mojo/public/c/system/types.h" |
23 #include "mojo/public/cpp/system/macros.h" | 22 #include "mojo/public/cpp/system/macros.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 size_t* actual_size, | 159 size_t* actual_size, |
161 embedder::PlatformHandleVector* platform_handles); | 160 embedder::PlatformHandleVector* platform_handles); |
162 bool ConsumerIsBusy() const; | 161 bool ConsumerIsBusy() const; |
163 | 162 |
164 // The following are only to be used by |DataPipeImpl| (and its subclasses): | 163 // The following are only to be used by |DataPipeImpl| (and its subclasses): |
165 | 164 |
166 // Replaces |impl_| with |new_impl| (which must not be null). For use when | 165 // Replaces |impl_| with |new_impl| (which must not be null). For use when |
167 // serializing data pipe dispatchers (i.e., in |ProducerEndSerialize()| and | 166 // serializing data pipe dispatchers (i.e., in |ProducerEndSerialize()| and |
168 // |ConsumerEndSerialize()|). Returns the old value of |impl_| (in case the | 167 // |ConsumerEndSerialize()|). Returns the old value of |impl_| (in case the |
169 // caller needs to manage its lifetime). | 168 // caller needs to manage its lifetime). |
170 scoped_ptr<DataPipeImpl> ReplaceImplNoLock(scoped_ptr<DataPipeImpl> new_impl) | 169 std::unique_ptr<DataPipeImpl> ReplaceImplNoLock( |
| 170 std::unique_ptr<DataPipeImpl> new_impl) |
171 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 171 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
172 void SetProducerClosedNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 172 void SetProducerClosedNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
173 void SetConsumerClosedNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 173 void SetConsumerClosedNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
174 | 174 |
175 void ProducerCloseNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 175 void ProducerCloseNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
176 void ConsumerCloseNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 176 void ConsumerCloseNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
177 | 177 |
178 // Thread-safe and fast (they don't take |mutex_|): | 178 // Thread-safe and fast (they don't take |mutex_|): |
179 const MojoCreateDataPipeOptions& validated_options() const { | 179 const MojoCreateDataPipeOptions& validated_options() const { |
180 return validated_options_; | 180 return validated_options_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // particular: |struct_size| is ignored (so |validated_options| must be the | 231 // particular: |struct_size| is ignored (so |validated_options| must be the |
232 // current version of the struct) and |capacity_num_bytes| must be nonzero. | 232 // current version of the struct) and |capacity_num_bytes| must be nonzero. |
233 // TODO(vtl): |has_local_producer|/|has_local_consumer| shouldn't really be | 233 // TODO(vtl): |has_local_producer|/|has_local_consumer| shouldn't really be |
234 // arguments here. Instead, they should be determined from the |impl| ... but | 234 // arguments here. Instead, they should be determined from the |impl| ... but |
235 // the |impl|'s typically figures these out by examining the owner, i.e., the | 235 // the |impl|'s typically figures these out by examining the owner, i.e., the |
236 // |DataPipe| object. Probably, this indicates that more stuff should be moved | 236 // |DataPipe| object. Probably, this indicates that more stuff should be moved |
237 // to |DataPipeImpl|, but for now we'll live with this. | 237 // to |DataPipeImpl|, but for now we'll live with this. |
238 DataPipe(bool has_local_producer, | 238 DataPipe(bool has_local_producer, |
239 bool has_local_consumer, | 239 bool has_local_consumer, |
240 const MojoCreateDataPipeOptions& validated_options, | 240 const MojoCreateDataPipeOptions& validated_options, |
241 scoped_ptr<DataPipeImpl> impl); | 241 std::unique_ptr<DataPipeImpl> impl); |
242 ~DataPipe() override; | 242 ~DataPipe() override; |
243 | 243 |
244 // |ChannelEndpointClient| implementation: | 244 // |ChannelEndpointClient| implementation: |
245 bool OnReadMessage(unsigned port, MessageInTransit* message) override; | 245 bool OnReadMessage(unsigned port, MessageInTransit* message) override; |
246 void OnDetachFromChannel(unsigned port) override; | 246 void OnDetachFromChannel(unsigned port) override; |
247 | 247 |
248 void AwakeProducerAwakablesForStateChangeNoLock( | 248 void AwakeProducerAwakablesForStateChangeNoLock( |
249 const HandleSignalsState& new_producer_state) | 249 const HandleSignalsState& new_producer_state) |
250 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 250 MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
251 void AwakeConsumerAwakablesForStateChangeNoLock( | 251 void AwakeConsumerAwakablesForStateChangeNoLock( |
(...skipping 18 matching lines...) Expand all Loading... |
270 mutable Mutex mutex_; | 270 mutable Mutex mutex_; |
271 // *Known* state of producer or consumer. | 271 // *Known* state of producer or consumer. |
272 bool producer_open_ MOJO_GUARDED_BY(mutex_); | 272 bool producer_open_ MOJO_GUARDED_BY(mutex_); |
273 bool consumer_open_ MOJO_GUARDED_BY(mutex_); | 273 bool consumer_open_ MOJO_GUARDED_BY(mutex_); |
274 // Non-null only if the producer or consumer, respectively, is local. | 274 // Non-null only if the producer or consumer, respectively, is local. |
275 std::unique_ptr<AwakableList> producer_awakable_list_ MOJO_GUARDED_BY(mutex_); | 275 std::unique_ptr<AwakableList> producer_awakable_list_ MOJO_GUARDED_BY(mutex_); |
276 std::unique_ptr<AwakableList> consumer_awakable_list_ MOJO_GUARDED_BY(mutex_); | 276 std::unique_ptr<AwakableList> consumer_awakable_list_ MOJO_GUARDED_BY(mutex_); |
277 // These are nonzero if and only if a two-phase write/read is in progress. | 277 // These are nonzero if and only if a two-phase write/read is in progress. |
278 uint32_t producer_two_phase_max_num_bytes_written_ MOJO_GUARDED_BY(mutex_); | 278 uint32_t producer_two_phase_max_num_bytes_written_ MOJO_GUARDED_BY(mutex_); |
279 uint32_t consumer_two_phase_max_num_bytes_read_ MOJO_GUARDED_BY(mutex_); | 279 uint32_t consumer_two_phase_max_num_bytes_read_ MOJO_GUARDED_BY(mutex_); |
280 scoped_ptr<DataPipeImpl> impl_ MOJO_GUARDED_BY(mutex_); | 280 std::unique_ptr<DataPipeImpl> impl_ MOJO_GUARDED_BY(mutex_); |
281 | 281 |
282 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe); | 282 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe); |
283 }; | 283 }; |
284 | 284 |
285 } // namespace system | 285 } // namespace system |
286 } // namespace mojo | 286 } // namespace mojo |
287 | 287 |
288 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_ | 288 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_ |
OLD | NEW |