| 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 #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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 MutexLocker locker(&mutex_); | 274 MutexLocker locker(&mutex_); |
| 275 DCHECK(has_local_producer_no_lock()); | 275 DCHECK(has_local_producer_no_lock()); |
| 276 producer_awakable_list_->CancelAll(); | 276 producer_awakable_list_->CancelAll(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void DataPipe::ProducerClose() { | 279 void DataPipe::ProducerClose() { |
| 280 MutexLocker locker(&mutex_); | 280 MutexLocker locker(&mutex_); |
| 281 ProducerCloseNoLock(); | 281 ProducerCloseNoLock(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 MojoResult DataPipe::ProducerSetOptions(uint32_t write_threshold_num_bytes) { |
| 285 MutexLocker locker(&mutex_); |
| 286 DCHECK(has_local_producer_no_lock()); |
| 287 |
| 288 if (write_threshold_num_bytes % element_num_bytes() != 0) |
| 289 return MOJO_RESULT_INVALID_ARGUMENT; |
| 290 |
| 291 HandleSignalsState old_producer_state = |
| 292 impl_->ProducerGetHandleSignalsState(); |
| 293 producer_write_threshold_num_bytes_ = write_threshold_num_bytes; |
| 294 HandleSignalsState new_producer_state = |
| 295 impl_->ProducerGetHandleSignalsState(); |
| 296 if (!new_producer_state.equals(old_producer_state)) |
| 297 AwakeProducerAwakablesForStateChangeNoLock(new_producer_state); |
| 298 return MOJO_RESULT_OK; |
| 299 } |
| 300 |
| 301 void DataPipe::ProducerGetOptions(uint32_t* write_threshold_num_bytes) { |
| 302 MutexLocker locker(&mutex_); |
| 303 DCHECK(has_local_producer_no_lock()); |
| 304 *write_threshold_num_bytes = producer_write_threshold_num_bytes_; |
| 305 } |
| 306 |
| 284 MojoResult DataPipe::ProducerWriteData(UserPointer<const void> elements, | 307 MojoResult DataPipe::ProducerWriteData(UserPointer<const void> elements, |
| 285 UserPointer<uint32_t> num_bytes, | 308 UserPointer<uint32_t> num_bytes, |
| 286 bool all_or_none) { | 309 bool all_or_none) { |
| 287 MutexLocker locker(&mutex_); | 310 MutexLocker locker(&mutex_); |
| 288 DCHECK(has_local_producer_no_lock()); | 311 DCHECK(has_local_producer_no_lock()); |
| 289 | 312 |
| 290 if (producer_in_two_phase_write_no_lock()) | 313 if (producer_in_two_phase_write_no_lock()) |
| 291 return MOJO_RESULT_BUSY; | 314 return MOJO_RESULT_BUSY; |
| 292 if (!consumer_open_no_lock()) | 315 if (!consumer_open_no_lock()) |
| 293 return MOJO_RESULT_FAILED_PRECONDITION; | 316 return MOJO_RESULT_FAILED_PRECONDITION; |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 } | 702 } |
| 680 | 703 |
| 681 DataPipe::DataPipe(bool has_local_producer, | 704 DataPipe::DataPipe(bool has_local_producer, |
| 682 bool has_local_consumer, | 705 bool has_local_consumer, |
| 683 const MojoCreateDataPipeOptions& validated_options, | 706 const MojoCreateDataPipeOptions& validated_options, |
| 684 std::unique_ptr<DataPipeImpl> impl) | 707 std::unique_ptr<DataPipeImpl> impl) |
| 685 : element_num_bytes_(validated_options.element_num_bytes), | 708 : element_num_bytes_(validated_options.element_num_bytes), |
| 686 capacity_num_bytes_(validated_options.capacity_num_bytes), | 709 capacity_num_bytes_(validated_options.capacity_num_bytes), |
| 687 producer_open_(true), | 710 producer_open_(true), |
| 688 consumer_open_(true), | 711 consumer_open_(true), |
| 712 producer_write_threshold_num_bytes_(0), |
| 689 consumer_read_threshold_num_bytes_(0), | 713 consumer_read_threshold_num_bytes_(0), |
| 690 producer_awakable_list_(has_local_producer ? new AwakableList() | 714 producer_awakable_list_(has_local_producer ? new AwakableList() |
| 691 : nullptr), | 715 : nullptr), |
| 692 consumer_awakable_list_(has_local_consumer ? new AwakableList() | 716 consumer_awakable_list_(has_local_consumer ? new AwakableList() |
| 693 : nullptr), | 717 : nullptr), |
| 694 producer_two_phase_max_num_bytes_written_(0), | 718 producer_two_phase_max_num_bytes_written_(0), |
| 695 consumer_two_phase_max_num_bytes_read_(0), | 719 consumer_two_phase_max_num_bytes_read_(0), |
| 696 impl_(std::move(impl)) { | 720 impl_(std::move(impl)) { |
| 697 impl_->set_owner(this); | 721 impl_->set_owner(this); |
| 698 | 722 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 SetProducerClosedNoLock(); | 858 SetProducerClosedNoLock(); |
| 835 } | 859 } |
| 836 | 860 |
| 837 void DataPipe::SetConsumerClosed() { | 861 void DataPipe::SetConsumerClosed() { |
| 838 MutexLocker locker(&mutex_); | 862 MutexLocker locker(&mutex_); |
| 839 SetConsumerClosedNoLock(); | 863 SetConsumerClosedNoLock(); |
| 840 } | 864 } |
| 841 | 865 |
| 842 } // namespace system | 866 } // namespace system |
| 843 } // namespace mojo | 867 } // namespace mojo |
| OLD | NEW |