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

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

Issue 2090763002: AwakableList: For persistent awakables, make Add() call Awake() with reason INITIALIZE. (Closed) Base URL: https://github.com/domokit/mojo.git@work795_wait_set_4.7-x-work794_wait_set_4.6
Patch Set: Created 4 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
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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 uint64_t context, 395 uint64_t context,
396 bool persistent, 396 bool persistent,
397 MojoHandleSignals signals, 397 MojoHandleSignals signals,
398 HandleSignalsState* signals_state) { 398 HandleSignalsState* signals_state) {
399 MutexLocker locker(&mutex_); 399 MutexLocker locker(&mutex_);
400 DCHECK(has_local_producer_no_lock()); 400 DCHECK(has_local_producer_no_lock());
401 401
402 HandleSignalsState producer_state = impl_->ProducerGetHandleSignalsState(); 402 HandleSignalsState producer_state = impl_->ProducerGetHandleSignalsState();
403 if (signals_state) 403 if (signals_state)
404 *signals_state = producer_state; 404 *signals_state = producer_state;
405 if (producer_state.satisfies(signals)) { 405 MojoResult rv = MOJO_RESULT_OK;
406 if (persistent) 406 bool should_add = persistent;
407 producer_awakable_list_->Add(awakable, context, persistent, signals); 407 if (producer_state.satisfies(signals))
408 return MOJO_RESULT_ALREADY_EXISTS; 408 rv = MOJO_RESULT_ALREADY_EXISTS;
409 else if (!producer_state.can_satisfy(signals))
410 rv = MOJO_RESULT_FAILED_PRECONDITION;
411 else
412 should_add = true;
413
414 if (should_add) {
415 producer_awakable_list_->Add(awakable, context, persistent, signals,
416 producer_state);
409 } 417 }
410 if (!producer_state.can_satisfy(signals)) { 418 return rv;
411 if (persistent)
412 producer_awakable_list_->Add(awakable, context, persistent, signals);
413 return MOJO_RESULT_FAILED_PRECONDITION;
414 }
415
416 producer_awakable_list_->Add(awakable, context, persistent, signals);
417 return MOJO_RESULT_OK;
418 } 419 }
419 420
420 void DataPipe::ProducerRemoveAwakable(bool match_context, 421 void DataPipe::ProducerRemoveAwakable(bool match_context,
421 Awakable* awakable, 422 Awakable* awakable,
422 uint64_t context, 423 uint64_t context,
423 HandleSignalsState* signals_state) { 424 HandleSignalsState* signals_state) {
424 MutexLocker locker(&mutex_); 425 MutexLocker locker(&mutex_);
425 DCHECK(has_local_producer_no_lock()); 426 DCHECK(has_local_producer_no_lock());
426 producer_awakable_list_->Remove(match_context, awakable, context); 427 producer_awakable_list_->Remove(match_context, awakable, context);
427 if (signals_state) 428 if (signals_state)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 uint64_t context, 610 uint64_t context,
610 bool persistent, 611 bool persistent,
611 MojoHandleSignals signals, 612 MojoHandleSignals signals,
612 HandleSignalsState* signals_state) { 613 HandleSignalsState* signals_state) {
613 MutexLocker locker(&mutex_); 614 MutexLocker locker(&mutex_);
614 DCHECK(has_local_consumer_no_lock()); 615 DCHECK(has_local_consumer_no_lock());
615 616
616 HandleSignalsState consumer_state = impl_->ConsumerGetHandleSignalsState(); 617 HandleSignalsState consumer_state = impl_->ConsumerGetHandleSignalsState();
617 if (signals_state) 618 if (signals_state)
618 *signals_state = consumer_state; 619 *signals_state = consumer_state;
619 if (consumer_state.satisfies(signals)) { 620 MojoResult rv = MOJO_RESULT_OK;
620 if (persistent) 621 bool should_add = persistent;
621 consumer_awakable_list_->Add(awakable, context, persistent, signals); 622 if (consumer_state.satisfies(signals))
622 return MOJO_RESULT_ALREADY_EXISTS; 623 rv = MOJO_RESULT_ALREADY_EXISTS;
624 else if (!consumer_state.can_satisfy(signals))
625 rv = MOJO_RESULT_FAILED_PRECONDITION;
626 else
627 should_add = true;
628
629 if (should_add) {
630 consumer_awakable_list_->Add(awakable, context, persistent, signals,
631 consumer_state);
623 } 632 }
624 if (!consumer_state.can_satisfy(signals)) { 633 return rv;
625 if (persistent)
626 consumer_awakable_list_->Add(awakable, context, persistent, signals);
627 return MOJO_RESULT_FAILED_PRECONDITION;
628 }
629
630 consumer_awakable_list_->Add(awakable, context, persistent, signals);
631 return MOJO_RESULT_OK;
632 } 634 }
633 635
634 void DataPipe::ConsumerRemoveAwakable(bool match_context, 636 void DataPipe::ConsumerRemoveAwakable(bool match_context,
635 Awakable* awakable, 637 Awakable* awakable,
636 uint64_t context, 638 uint64_t context,
637 HandleSignalsState* signals_state) { 639 HandleSignalsState* signals_state) {
638 MutexLocker locker(&mutex_); 640 MutexLocker locker(&mutex_);
639 DCHECK(has_local_consumer_no_lock()); 641 DCHECK(has_local_consumer_no_lock());
640 consumer_awakable_list_->Remove(match_context, awakable, context); 642 consumer_awakable_list_->Remove(match_context, awakable, context);
641 if (signals_state) 643 if (signals_state)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 SetProducerClosedNoLock(); 845 SetProducerClosedNoLock();
844 } 846 }
845 847
846 void DataPipe::SetConsumerClosed() { 848 void DataPipe::SetConsumerClosed() {
847 MutexLocker locker(&mutex_); 849 MutexLocker locker(&mutex_);
848 SetConsumerClosedNoLock(); 850 SetConsumerClosedNoLock();
849 } 851 }
850 852
851 } // namespace system 853 } // namespace system
852 } // namespace mojo 854 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/awakable_list_unittest.cc ('k') | mojo/edk/system/local_message_pipe_endpoint.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698