blob: 355677f7036771af72221e0ceee8d9d7c09b6f60 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "base/macros.h"
#include "mojo/edk/system/system_impl_export.h"
#include "mojo/edk/system/watcher.h"
#include "mojo/edk/system/watcher_set.h"
#include "mojo/public/c/system/types.h"
namespace mojo {
namespace edk {
class Awakable;
struct HandleSignalsState;
// |AwakableList| tracks all the |Waiter|s that are waiting on a given
// handle/|Dispatcher|. There should be a |AwakableList| for each handle that
// can be waited on (in any way). In the simple case, the |AwakableList| is
// owned by the |Dispatcher|, whereas in more complex cases it is owned by the
// secondary object (see simple_dispatcher.* and the explanatory comment in
// This class is thread-unsafe (all concurrent access must be
// protected by some lock).
class MOJO_SYSTEM_IMPL_EXPORT AwakableList {
void AwakeForStateChange(const HandleSignalsState& state);
void CancelAll();
void Add(Awakable* awakable, MojoHandleSignals signals, uintptr_t context);
void Remove(Awakable* awakable);
// Add and remove Watchers to this AwakableList.
MojoResult AddWatcher(MojoHandleSignals signals,
const Watcher::WatchCallback& callback,
uintptr_t context,
const HandleSignalsState& current_state);
MojoResult RemoveWatcher(uintptr_t context);
struct AwakeInfo {
AwakeInfo(Awakable* awakable, MojoHandleSignals signals, uintptr_t context)
: awakable(awakable), signals(signals), context(context) {}
Awakable* awakable;
MojoHandleSignals signals;
uintptr_t context;
using AwakeInfoList = std::vector<AwakeInfo>;
AwakeInfoList awakables_;
// TODO: Remove AwakableList and instead use WatcherSet directly in
// dispatchers.
WatcherSet watchers_;
} // namespace edk
} // namespace mojo