OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/edk/system/awakable_list.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "mojo/edk/system/awakable.h" |
| 9 #include "mojo/edk/system/handle_signals_state.h" |
| 10 |
| 11 namespace mojo { |
| 12 namespace system { |
| 13 |
| 14 AwakableList::AwakableList() { |
| 15 } |
| 16 |
| 17 AwakableList::~AwakableList() { |
| 18 DCHECK(awakables_.empty()); |
| 19 } |
| 20 |
| 21 void AwakableList::AwakeForStateChange(const HandleSignalsState& state) { |
| 22 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end(); |
| 23 ++it) { |
| 24 if (state.satisfies(it->signals)) |
| 25 it->awakable->Awake(MOJO_RESULT_OK, it->context); |
| 26 else if (!state.can_satisfy(it->signals)) |
| 27 it->awakable->Awake(MOJO_RESULT_FAILED_PRECONDITION, it->context); |
| 28 } |
| 29 } |
| 30 |
| 31 void AwakableList::CancelAll() { |
| 32 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end(); |
| 33 ++it) { |
| 34 it->awakable->Awake(MOJO_RESULT_CANCELLED, it->context); |
| 35 } |
| 36 awakables_.clear(); |
| 37 } |
| 38 |
| 39 void AwakableList::Add(Awakable* awakable, |
| 40 MojoHandleSignals signals, |
| 41 uint32_t context) { |
| 42 awakables_.push_back(AwakeInfo(awakable, signals, context)); |
| 43 } |
| 44 |
| 45 void AwakableList::Remove(Awakable* awakable) { |
| 46 // We allow a thread to wait on the same handle multiple times simultaneously, |
| 47 // so we need to scan the entire list and remove all occurrences of |waiter|. |
| 48 for (AwakeInfoList::iterator it = awakables_.begin(); |
| 49 it != awakables_.end();) { |
| 50 AwakeInfoList::iterator maybe_delete = it; |
| 51 ++it; |
| 52 if (maybe_delete->awakable == awakable) |
| 53 awakables_.erase(maybe_delete); |
| 54 } |
| 55 } |
| 56 |
| 57 } // namespace system |
| 58 } // namespace mojo |
OLD | NEW |