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

Side by Side Diff: mojo/system/local_data_pipe.cc

Issue 325213004: Mojo: Wrap the satisfied/unsatisfied wait flags state in a single object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/local_data_pipe.h ('k') | mojo/system/local_message_pipe_endpoint.h » ('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 // TODO(vtl): I currently potentially overflow in doing index calculations. 5 // TODO(vtl): I currently potentially overflow in doing index calculations.
6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but 6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but
7 // their sum may not. This is bad and poses a security risk. (We're currently 7 // their sum may not. This is bad and poses a security risk. (We're currently
8 // saved by the limit on capacity -- the maximum size of the buffer, checked in 8 // saved by the limit on capacity -- the maximum size of the buffer, checked in
9 // |DataPipe::ValidateOptions()|, is currently sufficiently small. 9 // |DataPipe::ValidateOptions()|, is currently sufficiently small.
10 10
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 MojoResult LocalDataPipe::ProducerEndWriteDataImplNoLock( 144 MojoResult LocalDataPipe::ProducerEndWriteDataImplNoLock(
145 uint32_t num_bytes_written) { 145 uint32_t num_bytes_written) {
146 DCHECK_LE(num_bytes_written, 146 DCHECK_LE(num_bytes_written,
147 producer_two_phase_max_num_bytes_written_no_lock()); 147 producer_two_phase_max_num_bytes_written_no_lock());
148 current_num_bytes_ += num_bytes_written; 148 current_num_bytes_ += num_bytes_written;
149 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); 149 DCHECK_LE(current_num_bytes_, capacity_num_bytes());
150 set_producer_two_phase_max_num_bytes_written_no_lock(0); 150 set_producer_two_phase_max_num_bytes_written_no_lock(0);
151 return MOJO_RESULT_OK; 151 return MOJO_RESULT_OK;
152 } 152 }
153 153
154 MojoWaitFlags LocalDataPipe::ProducerSatisfiedFlagsNoLock() { 154 WaitFlagsState LocalDataPipe::ProducerGetWaitFlagsStateNoLock() const {
155 MojoWaitFlags rv = MOJO_WAIT_FLAG_NONE; 155 WaitFlagsState rv;
156 if (consumer_open_no_lock() && 156 if (consumer_open_no_lock()) {
157 (may_discard() || current_num_bytes_ < capacity_num_bytes()) && 157 if ((may_discard() || current_num_bytes_ < capacity_num_bytes()) &&
158 !producer_in_two_phase_write_no_lock()) 158 !producer_in_two_phase_write_no_lock())
159 rv |= MOJO_WAIT_FLAG_WRITABLE; 159 rv.satisfied_flags |= MOJO_WAIT_FLAG_WRITABLE;
160 rv.satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE;
161 }
160 return rv; 162 return rv;
161 } 163 }
162 164
163 MojoWaitFlags LocalDataPipe::ProducerSatisfiableFlagsNoLock() {
164 MojoWaitFlags rv = MOJO_WAIT_FLAG_NONE;
165 if (consumer_open_no_lock())
166 rv |= MOJO_WAIT_FLAG_WRITABLE;
167 return rv;
168 }
169
170 void LocalDataPipe::ConsumerCloseImplNoLock() { 165 void LocalDataPipe::ConsumerCloseImplNoLock() {
171 // If the producer is around and in a two-phase write, we have to keep the 166 // If the producer is around and in a two-phase write, we have to keep the
172 // buffer around. (We then don't free it until the producer is closed. This 167 // buffer around. (We then don't free it until the producer is closed. This
173 // could be rectified, but again seems like optimizing for the uncommon case.) 168 // could be rectified, but again seems like optimizing for the uncommon case.)
174 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock()) 169 if (!producer_open_no_lock() || !producer_in_two_phase_write_no_lock())
175 DestroyBufferNoLock(); 170 DestroyBufferNoLock();
176 current_num_bytes_ = 0; 171 current_num_bytes_ = 0;
177 } 172 }
178 173
179 MojoResult LocalDataPipe::ConsumerReadDataImplNoLock(void* elements, 174 MojoResult LocalDataPipe::ConsumerReadDataImplNoLock(void* elements,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 266
272 MojoResult LocalDataPipe::ConsumerEndReadDataImplNoLock( 267 MojoResult LocalDataPipe::ConsumerEndReadDataImplNoLock(
273 uint32_t num_bytes_read) { 268 uint32_t num_bytes_read) {
274 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read_no_lock()); 269 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read_no_lock());
275 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); 270 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes());
276 MarkDataAsConsumedNoLock(num_bytes_read); 271 MarkDataAsConsumedNoLock(num_bytes_read);
277 set_consumer_two_phase_max_num_bytes_read_no_lock(0); 272 set_consumer_two_phase_max_num_bytes_read_no_lock(0);
278 return MOJO_RESULT_OK; 273 return MOJO_RESULT_OK;
279 } 274 }
280 275
281 MojoWaitFlags LocalDataPipe::ConsumerSatisfiedFlagsNoLock() { 276 WaitFlagsState LocalDataPipe::ConsumerGetWaitFlagsStateNoLock() const {
282 MojoWaitFlags rv = MOJO_WAIT_FLAG_NONE; 277 WaitFlagsState rv;
283 if (current_num_bytes_ > 0 && !consumer_in_two_phase_read_no_lock()) 278 if (current_num_bytes_ > 0) {
284 rv |= MOJO_WAIT_FLAG_READABLE; 279 if (!consumer_in_two_phase_read_no_lock())
280 rv.satisfied_flags |= MOJO_WAIT_FLAG_READABLE;
281 rv.satisfiable_flags |= MOJO_WAIT_FLAG_READABLE;
282 } else if (producer_open_no_lock()) {
283 rv.satisfiable_flags |= MOJO_WAIT_FLAG_READABLE;
284 }
285 return rv; 285 return rv;
286 } 286 }
287 287
288 MojoWaitFlags LocalDataPipe::ConsumerSatisfiableFlagsNoLock() {
289 MojoWaitFlags rv = MOJO_WAIT_FLAG_NONE;
290 if (current_num_bytes_ > 0 || producer_open_no_lock())
291 rv |= MOJO_WAIT_FLAG_READABLE;
292 return rv;
293 }
294
295 void LocalDataPipe::EnsureBufferNoLock() { 288 void LocalDataPipe::EnsureBufferNoLock() {
296 DCHECK(producer_open_no_lock()); 289 DCHECK(producer_open_no_lock());
297 if (buffer_.get()) 290 if (buffer_.get())
298 return; 291 return;
299 buffer_.reset(static_cast<char*>( 292 buffer_.reset(static_cast<char*>(
300 base::AlignedAlloc(capacity_num_bytes(), kDataPipeBufferAlignmentBytes))); 293 base::AlignedAlloc(capacity_num_bytes(), kDataPipeBufferAlignmentBytes)));
301 } 294 }
302 295
303 void LocalDataPipe::DestroyBufferNoLock() { 296 void LocalDataPipe::DestroyBufferNoLock() {
304 #ifndef NDEBUG 297 #ifndef NDEBUG
(...skipping 25 matching lines...) Expand all
330 323
331 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { 324 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) {
332 DCHECK_LE(num_bytes, current_num_bytes_); 325 DCHECK_LE(num_bytes, current_num_bytes_);
333 start_index_ += num_bytes; 326 start_index_ += num_bytes;
334 start_index_ %= capacity_num_bytes(); 327 start_index_ %= capacity_num_bytes();
335 current_num_bytes_ -= num_bytes; 328 current_num_bytes_ -= num_bytes;
336 } 329 }
337 330
338 } // namespace system 331 } // namespace system
339 } // namespace mojo 332 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/local_data_pipe.h ('k') | mojo/system/local_message_pipe_endpoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698