awakable_list.h revision 645501c2ab19a559ce82a1d5a29ced159a4c30fb
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// Copyright 2013 The Chromium Authors. All rights reserved.
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// Use of this source code is governed by a BSD-style license that can be
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// found in the LICENSE file.
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#ifndef MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#define MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <stddef.h>
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <stdint.h>
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include <vector>
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "base/macros.h"
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "mojo/edk/system/system_impl_export.h"
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "mojo/edk/system/watcher.h"
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "mojo/edk/system/watcher_set.h"
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#include "mojo/public/c/system/types.h"
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectnamespace mojo {
209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectnamespace edk {
219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectclass Awakable;
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectstruct HandleSignalsState;
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// |AwakableList| tracks all the |Waiter|s that are waiting on a given
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// handle/|Dispatcher|. There should be a |AwakableList| for each handle that
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// can be waited on (in any way). In the simple case, the |AwakableList| is
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// owned by the |Dispatcher|, whereas in more complex cases it is owned by the
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// secondary object (see simple_dispatcher.* and the explanatory comment in
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// core.cc). This class is thread-unsafe (all concurrent access must be
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project// protected by some lock).
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectclass MOJO_SYSTEM_IMPL_EXPORT AwakableList {
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public:
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  AwakableList();
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  ~AwakableList();
369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
37021627eb5875372dea57ba91fa782fffbfbbc559Alan Viverette  void AwakeForStateChange(const HandleSignalsState& state);
389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  void CancelAll();
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  void Add(Awakable* awakable, MojoHandleSignals signals, uintptr_t context);
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  void Remove(Awakable* awakable);
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  // Add and remove Watchers to this AwakableList.
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  MojoResult AddWatcher(MojoHandleSignals signals,
449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        const Watcher::WatchCallback& callback,
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        uintptr_t context,
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project                        const HandleSignalsState& current_state);
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  MojoResult RemoveWatcher(uintptr_t context);
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private:
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  struct AwakeInfo {
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    AwakeInfo(Awakable* awakable, MojoHandleSignals signals, uintptr_t context)
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        : awakable(awakable), signals(signals), context(context) {}
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    Awakable* awakable;
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    MojoHandleSignals signals;
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    uintptr_t context;
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  };
589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  using AwakeInfoList = std::vector<AwakeInfo>;
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  AwakeInfoList awakables_;
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  // TODO: Remove AwakableList and instead use WatcherSet directly in
639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  // dispatchers.
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  WatcherSet watchers_;
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  DISALLOW_COPY_AND_ASSIGN(AwakableList);
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project};
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}  // namespace edk
709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}  // namespace mojo
719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project#endif  // MOJO_EDK_SYSTEM_AWAKABLE_LIST_H_
739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project