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

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

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/data_pipe.h ('k') | mojo/edk/system/data_pipe_consumer_dispatcher.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 #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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 MutexLocker locker(&mutex_); 451 MutexLocker locker(&mutex_);
452 DCHECK(has_local_consumer_no_lock()); 452 DCHECK(has_local_consumer_no_lock());
453 consumer_awakable_list_->CancelAll(); 453 consumer_awakable_list_->CancelAll();
454 } 454 }
455 455
456 void DataPipe::ConsumerClose() { 456 void DataPipe::ConsumerClose() {
457 MutexLocker locker(&mutex_); 457 MutexLocker locker(&mutex_);
458 ConsumerCloseNoLock(); 458 ConsumerCloseNoLock();
459 } 459 }
460 460
461 MojoResult DataPipe::ConsumerSetOptions(uint32_t read_threshold_num_bytes) {
462 MutexLocker locker(&mutex_);
463 DCHECK(has_local_consumer_no_lock());
464
465 if (read_threshold_num_bytes % element_num_bytes() != 0)
466 return MOJO_RESULT_INVALID_ARGUMENT;
467
468 HandleSignalsState old_consumer_state =
469 impl_->ConsumerGetHandleSignalsState();
470 consumer_read_threshold_num_bytes_ = read_threshold_num_bytes;
471 HandleSignalsState new_consumer_state =
472 impl_->ConsumerGetHandleSignalsState();
473 if (!new_consumer_state.equals(old_consumer_state))
474 AwakeConsumerAwakablesForStateChangeNoLock(new_consumer_state);
475 return MOJO_RESULT_OK;
476 }
477
478 void DataPipe::ConsumerGetOptions(uint32_t* read_threshold_num_bytes) {
479 MutexLocker locker(&mutex_);
480 DCHECK(has_local_consumer_no_lock());
481 *read_threshold_num_bytes = consumer_read_threshold_num_bytes_;
482 }
483
461 MojoResult DataPipe::ConsumerReadData(UserPointer<void> elements, 484 MojoResult DataPipe::ConsumerReadData(UserPointer<void> elements,
462 UserPointer<uint32_t> num_bytes, 485 UserPointer<uint32_t> num_bytes,
463 bool all_or_none, 486 bool all_or_none,
464 bool peek) { 487 bool peek) {
465 MutexLocker locker(&mutex_); 488 MutexLocker locker(&mutex_);
466 DCHECK(has_local_consumer_no_lock()); 489 DCHECK(has_local_consumer_no_lock());
467 490
468 if (consumer_in_two_phase_read_no_lock()) 491 if (consumer_in_two_phase_read_no_lock())
469 return MOJO_RESULT_BUSY; 492 return MOJO_RESULT_BUSY;
470 493
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } 679 }
657 680
658 DataPipe::DataPipe(bool has_local_producer, 681 DataPipe::DataPipe(bool has_local_producer,
659 bool has_local_consumer, 682 bool has_local_consumer,
660 const MojoCreateDataPipeOptions& validated_options, 683 const MojoCreateDataPipeOptions& validated_options,
661 std::unique_ptr<DataPipeImpl> impl) 684 std::unique_ptr<DataPipeImpl> impl)
662 : element_num_bytes_(validated_options.element_num_bytes), 685 : element_num_bytes_(validated_options.element_num_bytes),
663 capacity_num_bytes_(validated_options.capacity_num_bytes), 686 capacity_num_bytes_(validated_options.capacity_num_bytes),
664 producer_open_(true), 687 producer_open_(true),
665 consumer_open_(true), 688 consumer_open_(true),
689 consumer_read_threshold_num_bytes_(0),
666 producer_awakable_list_(has_local_producer ? new AwakableList() 690 producer_awakable_list_(has_local_producer ? new AwakableList()
667 : nullptr), 691 : nullptr),
668 consumer_awakable_list_(has_local_consumer ? new AwakableList() 692 consumer_awakable_list_(has_local_consumer ? new AwakableList()
669 : nullptr), 693 : nullptr),
670 producer_two_phase_max_num_bytes_written_(0), 694 producer_two_phase_max_num_bytes_written_(0),
671 consumer_two_phase_max_num_bytes_read_(0), 695 consumer_two_phase_max_num_bytes_read_(0),
672 impl_(std::move(impl)) { 696 impl_(std::move(impl)) {
673 impl_->set_owner(this); 697 impl_->set_owner(this);
674 698
675 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 699 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 SetProducerClosedNoLock(); 834 SetProducerClosedNoLock();
811 } 835 }
812 836
813 void DataPipe::SetConsumerClosed() { 837 void DataPipe::SetConsumerClosed() {
814 MutexLocker locker(&mutex_); 838 MutexLocker locker(&mutex_);
815 SetConsumerClosedNoLock(); 839 SetConsumerClosedNoLock();
816 } 840 }
817 841
818 } // namespace system 842 } // namespace system
819 } // namespace mojo 843 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe.h ('k') | mojo/edk/system/data_pipe_consumer_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698