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

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

Issue 1365383004: Cleanup: Remove internal two-phase data pipe all-or-none support. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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/data_pipe.h ('k') | mojo/edk/system/data_pipe_consumer_dispatcher.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 #include "mojo/edk/system/data_pipe.h" 5 #include "mojo/edk/system/data_pipe.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 elements, num_bytes, max_num_bytes_to_write, min_num_bytes_to_write); 302 elements, num_bytes, max_num_bytes_to_write, min_num_bytes_to_write);
303 HandleSignalsState new_consumer_state = 303 HandleSignalsState new_consumer_state =
304 impl_->ConsumerGetHandleSignalsState(); 304 impl_->ConsumerGetHandleSignalsState();
305 if (!new_consumer_state.equals(old_consumer_state)) 305 if (!new_consumer_state.equals(old_consumer_state))
306 AwakeConsumerAwakablesForStateChangeNoLock(new_consumer_state); 306 AwakeConsumerAwakablesForStateChangeNoLock(new_consumer_state);
307 return rv; 307 return rv;
308 } 308 }
309 309
310 MojoResult DataPipe::ProducerBeginWriteData( 310 MojoResult DataPipe::ProducerBeginWriteData(
311 UserPointer<void*> buffer, 311 UserPointer<void*> buffer,
312 UserPointer<uint32_t> buffer_num_bytes, 312 UserPointer<uint32_t> buffer_num_bytes) {
313 bool all_or_none) {
314 MutexLocker locker(&mutex_); 313 MutexLocker locker(&mutex_);
315 DCHECK(has_local_producer_no_lock()); 314 DCHECK(has_local_producer_no_lock());
316 315
317 if (producer_in_two_phase_write_no_lock()) 316 if (producer_in_two_phase_write_no_lock())
318 return MOJO_RESULT_BUSY; 317 return MOJO_RESULT_BUSY;
319 if (!consumer_open_no_lock()) 318 if (!consumer_open_no_lock())
320 return MOJO_RESULT_FAILED_PRECONDITION; 319 return MOJO_RESULT_FAILED_PRECONDITION;
321 320
322 uint32_t min_num_bytes_to_write = 0; 321 MojoResult rv = impl_->ProducerBeginWriteData(buffer, buffer_num_bytes);
323 if (all_or_none) {
324 min_num_bytes_to_write = buffer_num_bytes.Get();
325 if (min_num_bytes_to_write % element_num_bytes() != 0)
326 return MOJO_RESULT_INVALID_ARGUMENT;
327 }
328
329 MojoResult rv = impl_->ProducerBeginWriteData(buffer, buffer_num_bytes,
330 min_num_bytes_to_write);
331 if (rv != MOJO_RESULT_OK) 322 if (rv != MOJO_RESULT_OK)
332 return rv; 323 return rv;
333 // Note: No need to awake producer awakables, even though we're going from 324 // Note: No need to awake producer awakables, even though we're going from
334 // writable to non-writable (since you can't wait on non-writability). 325 // writable to non-writable (since you can't wait on non-writability).
335 // Similarly, though this may have discarded data (in "may discard" mode), 326 // Similarly, though this may have discarded data (in "may discard" mode),
336 // making it non-readable, there's still no need to awake consumer awakables. 327 // making it non-readable, there's still no need to awake consumer awakables.
337 DCHECK(producer_in_two_phase_write_no_lock()); 328 DCHECK(producer_in_two_phase_write_no_lock());
338 return MOJO_RESULT_OK; 329 return MOJO_RESULT_OK;
339 } 330 }
340 331
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 517
527 if (consumer_in_two_phase_read_no_lock()) 518 if (consumer_in_two_phase_read_no_lock())
528 return MOJO_RESULT_BUSY; 519 return MOJO_RESULT_BUSY;
529 520
530 // Note: Don't need to validate |*num_bytes| for query. 521 // Note: Don't need to validate |*num_bytes| for query.
531 return impl_->ConsumerQueryData(num_bytes); 522 return impl_->ConsumerQueryData(num_bytes);
532 } 523 }
533 524
534 MojoResult DataPipe::ConsumerBeginReadData( 525 MojoResult DataPipe::ConsumerBeginReadData(
535 UserPointer<const void*> buffer, 526 UserPointer<const void*> buffer,
536 UserPointer<uint32_t> buffer_num_bytes, 527 UserPointer<uint32_t> buffer_num_bytes) {
537 bool all_or_none) {
538 MutexLocker locker(&mutex_); 528 MutexLocker locker(&mutex_);
539 DCHECK(has_local_consumer_no_lock()); 529 DCHECK(has_local_consumer_no_lock());
540 530
541 if (consumer_in_two_phase_read_no_lock()) 531 if (consumer_in_two_phase_read_no_lock())
542 return MOJO_RESULT_BUSY; 532 return MOJO_RESULT_BUSY;
543 533
544 uint32_t min_num_bytes_to_read = 0; 534 MojoResult rv = impl_->ConsumerBeginReadData(buffer, buffer_num_bytes);
545 if (all_or_none) {
546 min_num_bytes_to_read = buffer_num_bytes.Get();
547 if (min_num_bytes_to_read % element_num_bytes() != 0)
548 return MOJO_RESULT_INVALID_ARGUMENT;
549 }
550
551 MojoResult rv = impl_->ConsumerBeginReadData(buffer, buffer_num_bytes,
552 min_num_bytes_to_read);
553 if (rv != MOJO_RESULT_OK) 535 if (rv != MOJO_RESULT_OK)
554 return rv; 536 return rv;
555 DCHECK(consumer_in_two_phase_read_no_lock()); 537 DCHECK(consumer_in_two_phase_read_no_lock());
556 return MOJO_RESULT_OK; 538 return MOJO_RESULT_OK;
557 } 539 }
558 540
559 MojoResult DataPipe::ConsumerEndReadData(uint32_t num_bytes_read) { 541 MojoResult DataPipe::ConsumerEndReadData(uint32_t num_bytes_read) {
560 MutexLocker locker(&mutex_); 542 MutexLocker locker(&mutex_);
561 DCHECK(has_local_consumer_no_lock()); 543 DCHECK(has_local_consumer_no_lock());
562 544
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 SetProducerClosedNoLock(); 801 SetProducerClosedNoLock();
820 } 802 }
821 803
822 void DataPipe::SetConsumerClosed() { 804 void DataPipe::SetConsumerClosed() {
823 MutexLocker locker(&mutex_); 805 MutexLocker locker(&mutex_);
824 SetConsumerClosedNoLock(); 806 SetConsumerClosedNoLock();
825 } 807 }
826 808
827 } // namespace system 809 } // namespace system
828 } // namespace mojo 810 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe.h ('k') | mojo/edk/system/data_pipe_consumer_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698