| 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 399 |
| 400 MojoResult DataPipe::ProducerAddAwakable(Awakable* awakable, | 400 MojoResult DataPipe::ProducerAddAwakable(Awakable* awakable, |
| 401 MojoHandleSignals signals, | 401 MojoHandleSignals signals, |
| 402 bool force, | 402 bool force, |
| 403 uint64_t context, | 403 uint64_t context, |
| 404 HandleSignalsState* signals_state) { | 404 HandleSignalsState* signals_state) { |
| 405 MutexLocker locker(&mutex_); | 405 MutexLocker locker(&mutex_); |
| 406 DCHECK(has_local_producer_no_lock()); | 406 DCHECK(has_local_producer_no_lock()); |
| 407 | 407 |
| 408 HandleSignalsState producer_state = impl_->ProducerGetHandleSignalsState(); | 408 HandleSignalsState producer_state = impl_->ProducerGetHandleSignalsState(); |
| 409 if (signals_state) |
| 410 *signals_state = producer_state; |
| 409 if (producer_state.satisfies(signals)) { | 411 if (producer_state.satisfies(signals)) { |
| 410 if (force) | 412 if (force) |
| 411 producer_awakable_list_->Add(awakable, signals, context); | 413 producer_awakable_list_->Add(awakable, signals, context); |
| 412 if (signals_state) | |
| 413 *signals_state = producer_state; | |
| 414 return MOJO_RESULT_ALREADY_EXISTS; | 414 return MOJO_RESULT_ALREADY_EXISTS; |
| 415 } | 415 } |
| 416 if (!producer_state.can_satisfy(signals)) { | 416 if (!producer_state.can_satisfy(signals)) |
| 417 if (signals_state) | |
| 418 *signals_state = producer_state; | |
| 419 return MOJO_RESULT_FAILED_PRECONDITION; | 417 return MOJO_RESULT_FAILED_PRECONDITION; |
| 420 } | |
| 421 | 418 |
| 422 producer_awakable_list_->Add(awakable, signals, context); | 419 producer_awakable_list_->Add(awakable, signals, context); |
| 423 return MOJO_RESULT_OK; | 420 return MOJO_RESULT_OK; |
| 424 } | 421 } |
| 425 | 422 |
| 426 void DataPipe::ProducerRemoveAwakable(Awakable* awakable, | 423 void DataPipe::ProducerRemoveAwakable(Awakable* awakable, |
| 427 HandleSignalsState* signals_state) { | 424 HandleSignalsState* signals_state) { |
| 428 MutexLocker locker(&mutex_); | 425 MutexLocker locker(&mutex_); |
| 429 DCHECK(has_local_producer_no_lock()); | 426 DCHECK(has_local_producer_no_lock()); |
| 430 producer_awakable_list_->Remove(awakable); | 427 producer_awakable_list_->Remove(awakable); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 | 629 |
| 633 MojoResult DataPipe::ConsumerAddAwakable(Awakable* awakable, | 630 MojoResult DataPipe::ConsumerAddAwakable(Awakable* awakable, |
| 634 MojoHandleSignals signals, | 631 MojoHandleSignals signals, |
| 635 bool force, | 632 bool force, |
| 636 uint64_t context, | 633 uint64_t context, |
| 637 HandleSignalsState* signals_state) { | 634 HandleSignalsState* signals_state) { |
| 638 MutexLocker locker(&mutex_); | 635 MutexLocker locker(&mutex_); |
| 639 DCHECK(has_local_consumer_no_lock()); | 636 DCHECK(has_local_consumer_no_lock()); |
| 640 | 637 |
| 641 HandleSignalsState consumer_state = impl_->ConsumerGetHandleSignalsState(); | 638 HandleSignalsState consumer_state = impl_->ConsumerGetHandleSignalsState(); |
| 639 if (signals_state) |
| 640 *signals_state = consumer_state; |
| 642 if (consumer_state.satisfies(signals)) { | 641 if (consumer_state.satisfies(signals)) { |
| 643 if (force) | 642 if (force) |
| 644 consumer_awakable_list_->Add(awakable, signals, context); | 643 consumer_awakable_list_->Add(awakable, signals, context); |
| 645 if (signals_state) | |
| 646 *signals_state = consumer_state; | |
| 647 return MOJO_RESULT_ALREADY_EXISTS; | 644 return MOJO_RESULT_ALREADY_EXISTS; |
| 648 } | 645 } |
| 649 if (!consumer_state.can_satisfy(signals)) { | 646 if (!consumer_state.can_satisfy(signals)) |
| 650 if (signals_state) | |
| 651 *signals_state = consumer_state; | |
| 652 return MOJO_RESULT_FAILED_PRECONDITION; | 647 return MOJO_RESULT_FAILED_PRECONDITION; |
| 653 } | |
| 654 | 648 |
| 655 consumer_awakable_list_->Add(awakable, signals, context); | 649 consumer_awakable_list_->Add(awakable, signals, context); |
| 656 return MOJO_RESULT_OK; | 650 return MOJO_RESULT_OK; |
| 657 } | 651 } |
| 658 | 652 |
| 659 void DataPipe::ConsumerRemoveAwakable(Awakable* awakable, | 653 void DataPipe::ConsumerRemoveAwakable(Awakable* awakable, |
| 660 HandleSignalsState* signals_state) { | 654 HandleSignalsState* signals_state) { |
| 661 MutexLocker locker(&mutex_); | 655 MutexLocker locker(&mutex_); |
| 662 DCHECK(has_local_consumer_no_lock()); | 656 DCHECK(has_local_consumer_no_lock()); |
| 663 consumer_awakable_list_->Remove(awakable); | 657 consumer_awakable_list_->Remove(awakable); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 SetProducerClosedNoLock(); | 869 SetProducerClosedNoLock(); |
| 876 } | 870 } |
| 877 | 871 |
| 878 void DataPipe::SetConsumerClosed() { | 872 void DataPipe::SetConsumerClosed() { |
| 879 MutexLocker locker(&mutex_); | 873 MutexLocker locker(&mutex_); |
| 880 SetConsumerClosedNoLock(); | 874 SetConsumerClosedNoLock(); |
| 881 } | 875 } |
| 882 | 876 |
| 883 } // namespace system | 877 } // namespace system |
| 884 } // namespace mojo | 878 } // namespace mojo |
| OLD | NEW |