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/system/simple_dispatcher.h"
6
7#include "base/logging.h"
8
9namespace mojo {
10namespace system {
11
12SimpleDispatcher::SimpleDispatcher() {
13}
14
15SimpleDispatcher::~SimpleDispatcher() {
16}
17
18void SimpleDispatcher::StateChangedNoLock() {
19  lock().AssertAcquired();
20  waiter_list_.AwakeWaitersForStateChange(SatisfiedFlagsNoLock(),
21                                          SatisfiableFlagsNoLock());
22}
23
24void SimpleDispatcher::CancelAllWaitersNoLock() {
25  lock().AssertAcquired();
26  waiter_list_.CancelAllWaiters();
27}
28
29MojoResult SimpleDispatcher::AddWaiterImplNoLock(Waiter* waiter,
30                                                 MojoWaitFlags flags,
31                                                 MojoResult wake_result) {
32  lock().AssertAcquired();
33
34  if ((flags & SatisfiedFlagsNoLock()))
35    return MOJO_RESULT_ALREADY_EXISTS;
36  if (!(flags & SatisfiableFlagsNoLock()))
37    return MOJO_RESULT_FAILED_PRECONDITION;
38
39  waiter_list_.AddWaiter(waiter, flags, wake_result);
40  return MOJO_RESULT_OK;
41}
42
43void SimpleDispatcher::RemoveWaiterImplNoLock(Waiter* waiter) {
44  lock().AssertAcquired();
45  waiter_list_.RemoveWaiter(waiter);
46}
47
48}  // namespace system
49}  // namespace mojo
50