Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / system / simple_dispatcher.cc
blob19c302c403c362b994b1cfecd99905128ffe5ebd
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/system/simple_dispatcher.h"
7 #include "base/logging.h"
9 namespace mojo {
10 namespace system {
12 SimpleDispatcher::SimpleDispatcher() {
15 SimpleDispatcher::~SimpleDispatcher() {
18 void SimpleDispatcher::HandleSignalsStateChangedNoLock() {
19 lock().AssertAcquired();
20 waiter_list_.AwakeWaitersForStateChange(GetHandleSignalsStateImplNoLock());
23 void SimpleDispatcher::CancelAllWaitersNoLock() {
24 lock().AssertAcquired();
25 waiter_list_.CancelAllWaiters();
28 MojoResult SimpleDispatcher::AddWaiterImplNoLock(
29 Waiter* waiter,
30 MojoHandleSignals signals,
31 uint32_t context,
32 HandleSignalsState* signals_state) {
33 lock().AssertAcquired();
35 HandleSignalsState state(GetHandleSignalsStateImplNoLock());
36 if (state.satisfies(signals)) {
37 if (signals_state)
38 *signals_state = state;
39 return MOJO_RESULT_ALREADY_EXISTS;
41 if (!state.can_satisfy(signals)) {
42 if (signals_state)
43 *signals_state = state;
44 return MOJO_RESULT_FAILED_PRECONDITION;
47 waiter_list_.AddWaiter(waiter, signals, context);
48 return MOJO_RESULT_OK;
51 void SimpleDispatcher::RemoveWaiterImplNoLock(
52 Waiter* waiter,
53 HandleSignalsState* signals_state) {
54 lock().AssertAcquired();
55 waiter_list_.RemoveWaiter(waiter);
56 if (signals_state)
57 *signals_state = GetHandleSignalsStateImplNoLock();
60 } // namespace system
61 } // namespace mojo