| 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> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // failure (in which case |*data_pipe| may or may not be set to null). | 98 // failure (in which case |*data_pipe| may or may not be set to null). |
| 99 static bool ConsumerDeserialize(Channel* channel, | 99 static bool ConsumerDeserialize(Channel* channel, |
| 100 const void* source, | 100 const void* source, |
| 101 size_t size, | 101 size_t size, |
| 102 util::RefPtr<DataPipe>* data_pipe); | 102 util::RefPtr<DataPipe>* data_pipe); |
| 103 | 103 |
| 104 // These are called by the producer dispatcher to implement its methods of | 104 // These are called by the producer dispatcher to implement its methods of |
| 105 // corresponding names. | 105 // corresponding names. |
| 106 void ProducerCancelAllAwakables(); | 106 void ProducerCancelAllAwakables(); |
| 107 void ProducerClose(); | 107 void ProducerClose(); |
| 108 MojoResult ProducerSetOptions(uint32_t write_threshold_num_bytes); |
| 109 void ProducerGetOptions(uint32_t* write_threshold_num_bytes); |
| 108 MojoResult ProducerWriteData(UserPointer<const void> elements, | 110 MojoResult ProducerWriteData(UserPointer<const void> elements, |
| 109 UserPointer<uint32_t> num_bytes, | 111 UserPointer<uint32_t> num_bytes, |
| 110 bool all_or_none); | 112 bool all_or_none); |
| 111 MojoResult ProducerBeginWriteData(UserPointer<void*> buffer, | 113 MojoResult ProducerBeginWriteData(UserPointer<void*> buffer, |
| 112 UserPointer<uint32_t> buffer_num_bytes); | 114 UserPointer<uint32_t> buffer_num_bytes); |
| 113 MojoResult ProducerEndWriteData(uint32_t num_bytes_written); | 115 MojoResult ProducerEndWriteData(uint32_t num_bytes_written); |
| 114 HandleSignalsState ProducerGetHandleSignalsState(); | 116 HandleSignalsState ProducerGetHandleSignalsState(); |
| 115 MojoResult ProducerAddAwakable(Awakable* awakable, | 117 MojoResult ProducerAddAwakable(Awakable* awakable, |
| 116 MojoHandleSignals signals, | 118 MojoHandleSignals signals, |
| 117 uint32_t context, | 119 uint32_t context, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 192 |
| 191 // Must be called under |mutex_|. | 193 // Must be called under |mutex_|. |
| 192 bool producer_open_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) { | 194 bool producer_open_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) { |
| 193 mutex_.AssertHeld(); | 195 mutex_.AssertHeld(); |
| 194 return producer_open_; | 196 return producer_open_; |
| 195 } | 197 } |
| 196 bool consumer_open_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) { | 198 bool consumer_open_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) { |
| 197 mutex_.AssertHeld(); | 199 mutex_.AssertHeld(); |
| 198 return consumer_open_; | 200 return consumer_open_; |
| 199 } | 201 } |
| 202 // Note that this returns the "real" write threshold (never zero). |
| 203 size_t producer_write_threshold_num_bytes_no_lock() const |
| 204 MOJO_SHARED_LOCKS_REQUIRED(mutex_) { |
| 205 mutex_.AssertHeld(); |
| 206 return (producer_write_threshold_num_bytes_ > 0u) |
| 207 ? producer_write_threshold_num_bytes_ |
| 208 : element_num_bytes_; |
| 209 } |
| 200 // Note that this returns the "real" read threshold (never zero). | 210 // Note that this returns the "real" read threshold (never zero). |
| 201 size_t consumer_read_threshold_num_bytes_no_lock() const | 211 size_t consumer_read_threshold_num_bytes_no_lock() const |
| 202 MOJO_SHARED_LOCKS_REQUIRED(mutex_) { | 212 MOJO_SHARED_LOCKS_REQUIRED(mutex_) { |
| 203 mutex_.AssertHeld(); | 213 mutex_.AssertHeld(); |
| 204 return (consumer_read_threshold_num_bytes_ > 0u) | 214 return (consumer_read_threshold_num_bytes_ > 0u) |
| 205 ? consumer_read_threshold_num_bytes_ | 215 ? consumer_read_threshold_num_bytes_ |
| 206 : element_num_bytes_; | 216 : element_num_bytes_; |
| 207 } | 217 } |
| 208 uint32_t producer_two_phase_max_num_bytes_written_no_lock() const | 218 uint32_t producer_two_phase_max_num_bytes_written_no_lock() const |
| 209 MOJO_SHARED_LOCKS_REQUIRED(mutex_) { | 219 MOJO_SHARED_LOCKS_REQUIRED(mutex_) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 285 } |
| 276 | 286 |
| 277 const uint32_t element_num_bytes_; | 287 const uint32_t element_num_bytes_; |
| 278 const uint32_t capacity_num_bytes_; | 288 const uint32_t capacity_num_bytes_; |
| 279 | 289 |
| 280 mutable util::Mutex mutex_; | 290 mutable util::Mutex mutex_; |
| 281 // *Known* state of producer or consumer. | 291 // *Known* state of producer or consumer. |
| 282 bool producer_open_ MOJO_GUARDED_BY(mutex_); | 292 bool producer_open_ MOJO_GUARDED_BY(mutex_); |
| 283 bool consumer_open_ MOJO_GUARDED_BY(mutex_); | 293 bool consumer_open_ MOJO_GUARDED_BY(mutex_); |
| 284 // This may be zero (in which case it "means" |element_num_bytes_|). | 294 // This may be zero (in which case it "means" |element_num_bytes_|). |
| 295 uint32_t producer_write_threshold_num_bytes_ MOJO_GUARDED_BY(mutex_); |
| 296 // This may be zero (in which case it "means" |element_num_bytes_|). |
| 285 uint32_t consumer_read_threshold_num_bytes_ MOJO_GUARDED_BY(mutex_); | 297 uint32_t consumer_read_threshold_num_bytes_ MOJO_GUARDED_BY(mutex_); |
| 286 // Non-null only if the producer or consumer, respectively, is local. | 298 // Non-null only if the producer or consumer, respectively, is local. |
| 287 std::unique_ptr<AwakableList> producer_awakable_list_ MOJO_GUARDED_BY(mutex_); | 299 std::unique_ptr<AwakableList> producer_awakable_list_ MOJO_GUARDED_BY(mutex_); |
| 288 std::unique_ptr<AwakableList> consumer_awakable_list_ MOJO_GUARDED_BY(mutex_); | 300 std::unique_ptr<AwakableList> consumer_awakable_list_ MOJO_GUARDED_BY(mutex_); |
| 289 // These are nonzero if and only if a two-phase write/read is in progress. | 301 // These are nonzero if and only if a two-phase write/read is in progress. |
| 290 uint32_t producer_two_phase_max_num_bytes_written_ MOJO_GUARDED_BY(mutex_); | 302 uint32_t producer_two_phase_max_num_bytes_written_ MOJO_GUARDED_BY(mutex_); |
| 291 uint32_t consumer_two_phase_max_num_bytes_read_ MOJO_GUARDED_BY(mutex_); | 303 uint32_t consumer_two_phase_max_num_bytes_read_ MOJO_GUARDED_BY(mutex_); |
| 292 std::unique_ptr<DataPipeImpl> impl_ MOJO_GUARDED_BY(mutex_); | 304 std::unique_ptr<DataPipeImpl> impl_ MOJO_GUARDED_BY(mutex_); |
| 293 | 305 |
| 294 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe); | 306 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe); |
| 295 }; | 307 }; |
| 296 | 308 |
| 297 } // namespace system | 309 } // namespace system |
| 298 } // namespace mojo | 310 } // namespace mojo |
| 299 | 311 |
| 300 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_ | 312 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_ |
| OLD | NEW |