| 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/awakable_list.h" | 5 #include "mojo/edk/system/awakable_list.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/edk/system/awakable.h" | 10 #include "mojo/edk/system/awakable.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 for (auto it = awakables_.begin(); it != awakables_.end(); ++it) { | 69 for (auto it = awakables_.begin(); it != awakables_.end(); ++it) { |
| 70 it->awakable->Awake(it->context, Awakable::AwakeReason::CANCELLED, | 70 it->awakable->Awake(it->context, Awakable::AwakeReason::CANCELLED, |
| 71 HandleSignalsState()); | 71 HandleSignalsState()); |
| 72 } | 72 } |
| 73 awakables_.clear(); | 73 awakables_.clear(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void AwakableList::Add(Awakable* awakable, | 76 void AwakableList::Add(Awakable* awakable, |
| 77 uint64_t context, | 77 uint64_t context, |
| 78 bool persistent, | 78 bool persistent, |
| 79 MojoHandleSignals signals) { | 79 MojoHandleSignals signals, |
| 80 const HandleSignalsState& current_state) { |
| 80 awakables_.push_back(AwakeInfo(awakable, context, persistent, signals)); | 81 awakables_.push_back(AwakeInfo(awakable, context, persistent, signals)); |
| 82 if (persistent) |
| 83 awakable->Awake(context, Awakable::AwakeReason::INITIALIZE, current_state); |
| 81 } | 84 } |
| 82 | 85 |
| 83 void AwakableList::Remove(bool match_context, | 86 void AwakableList::Remove(bool match_context, |
| 84 Awakable* awakable, | 87 Awakable* awakable, |
| 85 uint64_t context) { | 88 uint64_t context) { |
| 86 // We allow a thread to wait on the same handle multiple times simultaneously, | 89 // We allow a thread to wait on the same handle multiple times simultaneously, |
| 87 // so we need to scan the entire list and remove all occurrences of |waiter|. | 90 // so we need to scan the entire list and remove all occurrences of |waiter|. |
| 88 auto last = awakables_.end(); | 91 auto last = awakables_.end(); |
| 89 for (AwakeInfoList::iterator it = awakables_.begin(); it != last;) { | 92 for (AwakeInfoList::iterator it = awakables_.begin(); it != last;) { |
| 90 if (it->awakable == awakable && | 93 if (it->awakable == awakable && |
| 91 (!match_context || it->context == context)) { | 94 (!match_context || it->context == context)) { |
| 92 --last; | 95 --last; |
| 93 std::swap(*it, *last); | 96 std::swap(*it, *last); |
| 94 } else { | 97 } else { |
| 95 ++it; | 98 ++it; |
| 96 } | 99 } |
| 97 } | 100 } |
| 98 awakables_.erase(last, awakables_.end()); | 101 awakables_.erase(last, awakables_.end()); |
| 99 } | 102 } |
| 100 | 103 |
| 101 } // namespace system | 104 } // namespace system |
| 102 } // namespace mojo | 105 } // namespace mojo |
| OLD | NEW |