Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: mojo/edk/system/data_pipe.h

Issue 1856113002: EDK: Add implementation of data pipe consumer read threshold stuff. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/core_unittest.cc ('k') | mojo/edk/system/data_pipe.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 Channel* channel, 125 Channel* channel,
126 void* destination, 126 void* destination,
127 size_t* actual_size, 127 size_t* actual_size,
128 std::vector<platform::ScopedPlatformHandle>* platform_handles); 128 std::vector<platform::ScopedPlatformHandle>* platform_handles);
129 bool ProducerIsBusy() const; 129 bool ProducerIsBusy() const;
130 130
131 // These are called by the consumer dispatcher to implement its methods of 131 // These are called by the consumer dispatcher to implement its methods of
132 // corresponding names. 132 // corresponding names.
133 void ConsumerCancelAllAwakables(); 133 void ConsumerCancelAllAwakables();
134 void ConsumerClose(); 134 void ConsumerClose();
135 MojoResult ConsumerSetOptions(uint32_t read_threshold_num_bytes);
136 void ConsumerGetOptions(uint32_t* read_threshold_num_bytes);
135 // This does not validate its arguments, except to check that |*num_bytes| is 137 // This does not validate its arguments, except to check that |*num_bytes| is
136 // a multiple of |element_num_bytes_|. 138 // a multiple of |element_num_bytes_|.
137 MojoResult ConsumerReadData(UserPointer<void> elements, 139 MojoResult ConsumerReadData(UserPointer<void> elements,
138 UserPointer<uint32_t> num_bytes, 140 UserPointer<uint32_t> num_bytes,
139 bool all_or_none, 141 bool all_or_none,
140 bool peek); 142 bool peek);
141 MojoResult ConsumerDiscardData(UserPointer<uint32_t> num_bytes, 143 MojoResult ConsumerDiscardData(UserPointer<uint32_t> num_bytes,
142 bool all_or_none); 144 bool all_or_none);
143 MojoResult ConsumerQueryData(UserPointer<uint32_t> num_bytes); 145 MojoResult ConsumerQueryData(UserPointer<uint32_t> num_bytes);
144 MojoResult ConsumerBeginReadData(UserPointer<const void*> buffer, 146 MojoResult ConsumerBeginReadData(UserPointer<const void*> buffer,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 190
189 // Must be called under |mutex_|. 191 // Must be called under |mutex_|.
190 bool producer_open_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) { 192 bool producer_open_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) {
191 mutex_.AssertHeld(); 193 mutex_.AssertHeld();
192 return producer_open_; 194 return producer_open_;
193 } 195 }
194 bool consumer_open_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) { 196 bool consumer_open_no_lock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_) {
195 mutex_.AssertHeld(); 197 mutex_.AssertHeld();
196 return consumer_open_; 198 return consumer_open_;
197 } 199 }
200 // Note that this returns the "real" read threshold (never zero).
201 size_t consumer_read_threshold_num_bytes_no_lock() const
202 MOJO_SHARED_LOCKS_REQUIRED(mutex_) {
203 mutex_.AssertHeld();
204 return (consumer_read_threshold_num_bytes_ > 0u)
205 ? consumer_read_threshold_num_bytes_
206 : element_num_bytes_;
207 }
198 uint32_t producer_two_phase_max_num_bytes_written_no_lock() const 208 uint32_t producer_two_phase_max_num_bytes_written_no_lock() const
199 MOJO_SHARED_LOCKS_REQUIRED(mutex_) { 209 MOJO_SHARED_LOCKS_REQUIRED(mutex_) {
200 mutex_.AssertHeld(); 210 mutex_.AssertHeld();
201 return producer_two_phase_max_num_bytes_written_; 211 return producer_two_phase_max_num_bytes_written_;
202 } 212 }
203 uint32_t consumer_two_phase_max_num_bytes_read_no_lock() const 213 uint32_t consumer_two_phase_max_num_bytes_read_no_lock() const
204 MOJO_SHARED_LOCKS_REQUIRED(mutex_) { 214 MOJO_SHARED_LOCKS_REQUIRED(mutex_) {
205 mutex_.AssertHeld(); 215 mutex_.AssertHeld();
206 return consumer_two_phase_max_num_bytes_read_; 216 return consumer_two_phase_max_num_bytes_read_;
207 } 217 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return !!consumer_awakable_list_; 274 return !!consumer_awakable_list_;
265 } 275 }
266 276
267 const uint32_t element_num_bytes_; 277 const uint32_t element_num_bytes_;
268 const uint32_t capacity_num_bytes_; 278 const uint32_t capacity_num_bytes_;
269 279
270 mutable util::Mutex mutex_; 280 mutable util::Mutex mutex_;
271 // *Known* state of producer or consumer. 281 // *Known* state of producer or consumer.
272 bool producer_open_ MOJO_GUARDED_BY(mutex_); 282 bool producer_open_ MOJO_GUARDED_BY(mutex_);
273 bool consumer_open_ MOJO_GUARDED_BY(mutex_); 283 bool consumer_open_ MOJO_GUARDED_BY(mutex_);
284 // This may be zero (in which case it "means" |element_num_bytes_|).
285 uint32_t consumer_read_threshold_num_bytes_ MOJO_GUARDED_BY(mutex_);
274 // Non-null only if the producer or consumer, respectively, is local. 286 // Non-null only if the producer or consumer, respectively, is local.
275 std::unique_ptr<AwakableList> producer_awakable_list_ MOJO_GUARDED_BY(mutex_); 287 std::unique_ptr<AwakableList> producer_awakable_list_ MOJO_GUARDED_BY(mutex_);
276 std::unique_ptr<AwakableList> consumer_awakable_list_ MOJO_GUARDED_BY(mutex_); 288 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. 289 // 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_); 290 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_); 291 uint32_t consumer_two_phase_max_num_bytes_read_ MOJO_GUARDED_BY(mutex_);
280 std::unique_ptr<DataPipeImpl> impl_ MOJO_GUARDED_BY(mutex_); 292 std::unique_ptr<DataPipeImpl> impl_ MOJO_GUARDED_BY(mutex_);
281 293
282 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe); 294 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe);
283 }; 295 };
284 296
285 } // namespace system 297 } // namespace system
286 } // namespace mojo 298 } // namespace mojo
287 299
288 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_ 300 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/core_unittest.cc ('k') | mojo/edk/system/data_pipe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698