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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/edk/system/awakable.h" | 8 #include "mojo/edk/system/awakable.h" |
9 #include "mojo/edk/system/handle_signals_state.h" | 9 #include "mojo/edk/system/handle_signals_state.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace system { | 12 namespace system { |
13 | 13 |
14 AwakableList::AwakableList() { | 14 AwakableList::AwakableList() { |
15 } | 15 } |
16 | 16 |
17 AwakableList::~AwakableList() { | 17 AwakableList::~AwakableList() { |
18 DCHECK(awakables_.empty()); | 18 DCHECK(awakables_.empty()); |
19 } | 19 } |
20 | 20 |
21 void AwakableList::AwakeForStateChange(const HandleSignalsState& state) { | 21 void AwakableList::AwakeForStateChange(const HandleSignalsState& state) { |
22 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end(); | 22 for (AwakeInfoList::iterator it = awakables_.begin(); |
23 ++it) { | 23 it != awakables_.end();) { |
| 24 bool keep = true; |
24 if (state.satisfies(it->signals)) | 25 if (state.satisfies(it->signals)) |
25 it->awakable->Awake(MOJO_RESULT_OK, it->context); | 26 keep = it->awakable->Awake(MOJO_RESULT_OK, it->context); |
26 else if (!state.can_satisfy(it->signals)) | 27 else if (!state.can_satisfy(it->signals)) |
27 it->awakable->Awake(MOJO_RESULT_FAILED_PRECONDITION, it->context); | 28 keep = it->awakable->Awake(MOJO_RESULT_FAILED_PRECONDITION, it->context); |
| 29 AwakeInfoList::iterator maybe_delete = it; |
| 30 ++it; |
| 31 |
| 32 if (!keep) |
| 33 awakables_.erase(maybe_delete); |
28 } | 34 } |
29 } | 35 } |
30 | 36 |
31 void AwakableList::CancelAll() { | 37 void AwakableList::CancelAll() { |
32 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end(); | 38 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end(); |
33 ++it) { | 39 ++it) { |
34 it->awakable->Awake(MOJO_RESULT_CANCELLED, it->context); | 40 it->awakable->Awake(MOJO_RESULT_CANCELLED, it->context); |
35 } | 41 } |
36 awakables_.clear(); | 42 awakables_.clear(); |
37 } | 43 } |
(...skipping 11 matching lines...) Expand all Loading... |
49 it != awakables_.end();) { | 55 it != awakables_.end();) { |
50 AwakeInfoList::iterator maybe_delete = it; | 56 AwakeInfoList::iterator maybe_delete = it; |
51 ++it; | 57 ++it; |
52 if (maybe_delete->awakable == awakable) | 58 if (maybe_delete->awakable == awakable) |
53 awakables_.erase(maybe_delete); | 59 awakables_.erase(maybe_delete); |
54 } | 60 } |
55 } | 61 } |
56 | 62 |
57 } // namespace system | 63 } // namespace system |
58 } // namespace mojo | 64 } // namespace mojo |
OLD | NEW |