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

Unified Diff: mojo/edk/system/awakable_list.cc

Issue 2088833003: Add different behavior to AwakableList for "persistent" vs "one-shot" awakables. (Closed) Base URL: https://github.com/domokit/mojo.git@work793_wait_set_4.5
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/awakable_list.h ('k') | mojo/edk/system/awakable_list_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/awakable_list.cc
diff --git a/mojo/edk/system/awakable_list.cc b/mojo/edk/system/awakable_list.cc
index fb432b91dc67dc087e34d82a9cab792558402277..3c3799a0bf4b35b547ba68c713b02b144d5c1cc4 100644
--- a/mojo/edk/system/awakable_list.cc
+++ b/mojo/edk/system/awakable_list.cc
@@ -24,18 +24,35 @@ void AwakableList::OnStateChange(const HandleSignalsState& old_state,
// Instead of deleting elements in-place, swap them with the last element and
// erase the elements from the end.
auto last = awakables_.end();
- for (AwakeInfoList::iterator it = awakables_.begin(); it != last;) {
- bool keep = true;
- if (new_state.satisfies(it->signals) && !old_state.satisfies(it->signals)) {
- keep = it->awakable->Awake(it->context, Awakable::AwakeReason::SATISFIED,
- new_state);
- } else if (!new_state.can_satisfy(it->signals) &&
- old_state.can_satisfy(it->signals)) {
- keep = it->awakable->Awake(
- it->context, Awakable::AwakeReason::UNSATISFIABLE, new_state);
+ for (auto it = awakables_.begin(); it != last;) {
+ bool awoken = false;
+ if (it->persistent) {
+ // Persistent awakables are called for all changes on watched signals.
+ if ((new_state.satisfied_signals & it->signals) !=
+ (old_state.satisfied_signals & it->signals) ||
+ (new_state.satisfiable_signals & it->signals) !=
+ (old_state.satisfiable_signals & it->signals)) {
+ awoken = true;
+ it->awakable->Awake(it->context, Awakable::AwakeReason::CHANGED,
+ new_state);
+ }
+ } else {
+ // One-shot awakables are only called on "leading edge" changes.
+ if (new_state.satisfies(it->signals) &&
+ !old_state.satisfies(it->signals)) {
+ awoken = true;
+ it->awakable->Awake(it->context, Awakable::AwakeReason::SATISFIED,
+ new_state);
+ } else if (!new_state.can_satisfy(it->signals) &&
+ old_state.can_satisfy(it->signals)) {
+ awoken = true;
+ it->awakable->Awake(it->context, Awakable::AwakeReason::UNSATISFIABLE,
+ new_state);
+ }
}
- if (!keep) {
+ // Remove if the awakable was awoken and one-shot.
+ if (awoken && !it->persistent) {
--last;
std::swap(*it, *last);
} else {
@@ -45,9 +62,8 @@ void AwakableList::OnStateChange(const HandleSignalsState& old_state,
awakables_.erase(last, awakables_.end());
}
-void AwakableList::CancelAll() {
- for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end();
- ++it) {
+void AwakableList::CancelAndRemoveAll() {
+ for (auto it = awakables_.begin(); it != awakables_.end(); ++it) {
it->awakable->Awake(it->context, Awakable::AwakeReason::CANCELLED,
HandleSignalsState());
}
@@ -56,8 +72,9 @@ void AwakableList::CancelAll() {
void AwakableList::Add(Awakable* awakable,
uint64_t context,
+ bool persistent,
MojoHandleSignals signals) {
- awakables_.push_back(AwakeInfo(awakable, signals, context));
+ awakables_.push_back(AwakeInfo(awakable, context, persistent, signals));
}
void AwakableList::Remove(bool match_context,
« no previous file with comments | « mojo/edk/system/awakable_list.h ('k') | mojo/edk/system/awakable_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698