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

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

Issue 2084593005: Rationalize AddAwakable...() and RemoveAwakable...() methods. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 void AwakableList::CancelAll() { 48 void AwakableList::CancelAll() {
49 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end(); 49 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end();
50 ++it) { 50 ++it) {
51 it->awakable->Awake(it->context, Awakable::AwakeReason::CANCELLED, 51 it->awakable->Awake(it->context, Awakable::AwakeReason::CANCELLED,
52 HandleSignalsState()); 52 HandleSignalsState());
53 } 53 }
54 awakables_.clear(); 54 awakables_.clear();
55 } 55 }
56 56
57 void AwakableList::Add(Awakable* awakable, 57 void AwakableList::Add(Awakable* awakable,
58 MojoHandleSignals signals, 58 uint64_t context,
59 uint64_t context) { 59 MojoHandleSignals signals) {
60 awakables_.push_back(AwakeInfo(awakable, signals, context)); 60 awakables_.push_back(AwakeInfo(awakable, signals, context));
61 } 61 }
62 62
63 void AwakableList::Remove(Awakable* awakable) { 63 void AwakableList::Remove(bool match_context,
64 Awakable* awakable,
65 uint64_t context) {
64 // We allow a thread to wait on the same handle multiple times simultaneously, 66 // We allow a thread to wait on the same handle multiple times simultaneously,
65 // so we need to scan the entire list and remove all occurrences of |waiter|. 67 // so we need to scan the entire list and remove all occurrences of |waiter|.
66 auto last = awakables_.end(); 68 auto last = awakables_.end();
67 for (AwakeInfoList::iterator it = awakables_.begin(); it != last;) { 69 for (AwakeInfoList::iterator it = awakables_.begin(); it != last;) {
68 if (it->awakable == awakable) { 70 if (it->awakable == awakable &&
71 (!match_context || it->context == context)) {
69 --last; 72 --last;
70 std::swap(*it, *last); 73 std::swap(*it, *last);
71 } else { 74 } else {
72 ++it;
73 }
74 }
75 awakables_.erase(last, awakables_.end());
76 }
77
78 void AwakableList::RemoveWithContext(Awakable* awakable, uint64_t context) {
79 // We allow a thread to wait on the same handle multiple times simultaneously,
80 // so we need to scan the entire list and remove all occurrences of |waiter|.
81 auto last = awakables_.end();
82 for (AwakeInfoList::iterator it = awakables_.begin(); it != last;) {
83 if (it->awakable == awakable && it->context == context) {
84 --last;
85 std::swap(*it, *last);
86 } else {
87 ++it; 75 ++it;
88 } 76 }
89 } 77 }
90 awakables_.erase(last, awakables_.end()); 78 awakables_.erase(last, awakables_.end());
91 } 79 }
92 80
93 } // namespace system 81 } // namespace system
94 } // namespace mojo 82 } // namespace mojo
OLDNEW
« 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