tuple: update to make use of C++11
[chromium-blink-merge.git] / mojo / edk / system / awakable_list.cc
blob6af305b4420e2799ede060085e9ae914c03d22e4
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.
5 #include "mojo/edk/system/awakable_list.h"
7 #include "base/logging.h"
8 #include "mojo/edk/system/awakable.h"
9 #include "mojo/edk/system/handle_signals_state.h"
11 namespace mojo {
12 namespace system {
14 AwakableList::AwakableList() {
17 AwakableList::~AwakableList() {
18 DCHECK(awakables_.empty());
21 void AwakableList::AwakeForStateChange(const HandleSignalsState& state) {
22 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end();
23 ++it) {
24 if (state.satisfies(it->signals))
25 it->awakable->Awake(MOJO_RESULT_OK, it->context);
26 else if (!state.can_satisfy(it->signals))
27 it->awakable->Awake(MOJO_RESULT_FAILED_PRECONDITION, it->context);
31 void AwakableList::CancelAll() {
32 for (AwakeInfoList::iterator it = awakables_.begin(); it != awakables_.end();
33 ++it) {
34 it->awakable->Awake(MOJO_RESULT_CANCELLED, it->context);
36 awakables_.clear();
39 void AwakableList::Add(Awakable* awakable,
40 MojoHandleSignals signals,
41 uint32_t context) {
42 awakables_.push_back(AwakeInfo(awakable, signals, context));
45 void AwakableList::Remove(Awakable* awakable) {
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 (AwakeInfoList::iterator it = awakables_.begin();
49 it != awakables_.end();) {
50 AwakeInfoList::iterator maybe_delete = it;
51 ++it;
52 if (maybe_delete->awakable == awakable)
53 awakables_.erase(maybe_delete);
57 } // namespace system
58 } // namespace mojo