File: wait_set_dispatcher.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (103 lines) | stat: -rw-r--r-- 3,409 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2015 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.

#ifndef MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_
#define MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_

#include <stdint.h>

#include <deque>
#include <memory>
#include <unordered_map>
#include <utility>

#include "base/macros.h"
#include "base/synchronization/lock.h"
#include "mojo/edk/system/awakable_list.h"
#include "mojo/edk/system/dispatcher.h"
#include "mojo/edk/system/system_impl_export.h"

namespace mojo {
namespace edk {

class MOJO_SYSTEM_IMPL_EXPORT WaitSetDispatcher : public Dispatcher {
 public:
  WaitSetDispatcher();

  // Dispatcher:
  Type GetType() const override;
  MojoResult Close() override;
  MojoResult AddWaitingDispatcher(const scoped_refptr<Dispatcher>& dispatcher,
                                  MojoHandleSignals signals,
                                  uintptr_t context) override;
  MojoResult RemoveWaitingDispatcher(
      const scoped_refptr<Dispatcher>& dispatcher) override;
  MojoResult GetReadyDispatchers(uint32_t* count,
                                 DispatcherVector* dispatchers,
                                 MojoResult* results,
                                 uintptr_t* contexts) override;
  HandleSignalsState GetHandleSignalsState() const override;
  MojoResult AddAwakable(Awakable* awakable,
                         MojoHandleSignals signals,
                         uintptr_t context,
                         HandleSignalsState* signals_state) override;
  void RemoveAwakable(Awakable* awakable,
                      HandleSignalsState* signals_state) override;
  bool BeginTransit() override;

 private:
  // Internal implementation of Awakable.
  class Waiter;

  struct WaitState {
    WaitState();
    WaitState(const WaitState& other);
    ~WaitState();

    scoped_refptr<Dispatcher> dispatcher;
    MojoHandleSignals signals;
    uintptr_t context;
  };

  ~WaitSetDispatcher() override;

  HandleSignalsState GetHandleSignalsStateNoLock() const;

  // Signal that the dispatcher indexed by |context| has been woken up with
  // |result| and is now ready.
  void WakeDispatcher(MojoResult result, uintptr_t context);

  // Guards |is_closed_|, |waiting_dispatchers_|, and |waiter_|.
  //
  // TODO: Consider removing this.
  mutable base::Lock lock_;
  bool is_closed_ = false;

  // Map of dispatchers being waited on. Key is a Dispatcher* casted to a
  // uintptr_t, and should be treated as an opaque value and not casted back.
  std::unordered_map<uintptr_t, WaitState> waiting_dispatchers_;

  // Separate lock that can be locked without locking |lock_|.
  mutable base::Lock awoken_lock_;
  // List of dispatchers that have been woken up. Any dispatcher in this queue
  // will NOT currently be waited on.
  std::deque<std::pair<uintptr_t, MojoResult>> awoken_queue_;
  // List of dispatchers that have been woken up and retrieved.
  std::deque<uintptr_t> processed_dispatchers_;

  // Separate lock that can be locked without locking |lock_|.
  base::Lock awakable_lock_;
  // List of dispatchers being waited on.
  AwakableList awakable_list_;

  // Waiter used to wait on dispatchers.
  std::unique_ptr<Waiter> waiter_;

  DISALLOW_COPY_AND_ASSIGN(WaitSetDispatcher);
};

}  // namespace edk
}  // namespace mojo

#endif  // MOJO_EDK_SYSTEM_WAIT_SET_DISPATCHER_H_