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

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

Issue 782693004: Update mojo sdk to rev f6c8ec07c01deebc13178d516225fd12695c3dc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack mojo_system_impl gypi for android :| Created 6 years 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
OLDNEW
(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/waiter_list.h"
6
7 #include "base/logging.h"
8 #include "mojo/edk/system/handle_signals_state.h"
9 #include "mojo/edk/system/waiter.h"
10
11 namespace mojo {
12 namespace system {
13
14 WaiterList::WaiterList() {
15 }
16
17 WaiterList::~WaiterList() {
18 DCHECK(waiters_.empty());
19 }
20
21 void WaiterList::AwakeWaitersForStateChange(const HandleSignalsState& state) {
22 for (WaiterInfoList::iterator it = waiters_.begin(); it != waiters_.end();
23 ++it) {
24 if (state.satisfies(it->signals))
25 it->waiter->Awake(MOJO_RESULT_OK, it->context);
26 else if (!state.can_satisfy(it->signals))
27 it->waiter->Awake(MOJO_RESULT_FAILED_PRECONDITION, it->context);
28 }
29 }
30
31 void WaiterList::CancelAllWaiters() {
32 for (WaiterInfoList::iterator it = waiters_.begin(); it != waiters_.end();
33 ++it) {
34 it->waiter->Awake(MOJO_RESULT_CANCELLED, it->context);
35 }
36 waiters_.clear();
37 }
38
39 void WaiterList::AddWaiter(Waiter* waiter,
40 MojoHandleSignals signals,
41 uint32_t context) {
42 waiters_.push_back(WaiterInfo(waiter, signals, context));
43 }
44
45 void WaiterList::RemoveWaiter(Waiter* waiter) {
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 (WaiterInfoList::iterator it = waiters_.begin(); it != waiters_.end();) {
49 WaiterInfoList::iterator maybe_delete = it;
50 ++it;
51 if (maybe_delete->waiter == waiter)
52 waiters_.erase(maybe_delete);
53 }
54 }
55
56 } // namespace system
57 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698