OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_MESSAGE_PUMP_MESSAGE_PUMP_MOJO_H_ | 5 #ifndef MOJO_MESSAGE_PUMP_MESSAGE_PUMP_MOJO_H_ |
6 #define MOJO_MESSAGE_PUMP_MESSAGE_PUMP_MOJO_H_ | 6 #define MOJO_MESSAGE_PUMP_MESSAGE_PUMP_MOJO_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 void RemoveObserver(Observer*); | 62 void RemoveObserver(Observer*); |
63 | 63 |
64 // MessagePump: | 64 // MessagePump: |
65 void Run(Delegate* delegate) override; | 65 void Run(Delegate* delegate) override; |
66 void Quit() override; | 66 void Quit() override; |
67 void ScheduleWork() override; | 67 void ScheduleWork() override; |
68 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override; | 68 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override; |
69 | 69 |
70 private: | 70 private: |
71 struct RunState; | 71 struct RunState; |
72 struct WaitState; | |
73 | 72 |
74 // Contains the data needed to track a request to AddHandler(). | 73 // Contains the data needed to track a request to AddHandler(). |
75 struct Handler { | 74 struct Handler { |
76 Handler() : handler(NULL), wait_signals(MOJO_HANDLE_SIGNAL_NONE), id(0) {} | 75 Handler() : handler(NULL), wait_signals(MOJO_HANDLE_SIGNAL_NONE), id(0) {} |
77 | 76 |
78 MessagePumpMojoHandler* handler; | 77 MessagePumpMojoHandler* handler; |
79 MojoHandleSignals wait_signals; | 78 MojoHandleSignals wait_signals; |
80 base::TimeTicks deadline; | 79 base::TimeTicks deadline; |
81 // See description of |MessagePumpMojo::next_handler_id_| for details. | 80 // See description of |MessagePumpMojo::next_handler_id_| for details. |
82 int id; | 81 int id; |
83 }; | 82 }; |
84 | 83 |
85 typedef std::map<Handle, Handler> HandleToHandler; | 84 typedef std::map<Handle, Handler> HandleToHandler; |
86 | 85 |
87 // Implementation of Run(). | 86 // Implementation of Run(). |
88 void DoRunLoop(RunState* run_state, Delegate* delegate); | 87 void DoRunLoop(RunState* run_state, Delegate* delegate); |
89 | 88 |
90 // Services the set of handles ready. If |block| is true this waits for a | 89 // Services the set of handles ready. If |block| is true this waits for a |
91 // handle to become ready, otherwise this does not block. Returns |true| if a | 90 // handle to become ready, otherwise this does not block. Returns |true| if a |
92 // handle has become ready, |false| otherwise. | 91 // handle has become ready, |false| otherwise. |
93 bool DoInternalWork(const RunState& run_state, bool block); | 92 bool DoInternalWork(const RunState& run_state, bool block); |
94 | 93 |
95 // Removes the given invalid handle. This is called if MojoWaitMany finds an | 94 // Removes the given invalid handle. This is called if MojoWaitMany finds an |
96 // invalid handle. | 95 // invalid handle. |
97 void RemoveInvalidHandle(const WaitState& wait_state, | 96 void RemoveInvalidHandle(MojoResult result, Handle handle); |
98 MojoResult result, | |
99 uint32_t result_index); | |
100 | 97 |
101 void SignalControlPipe(); | 98 void SignalControlPipe(); |
102 | 99 |
103 WaitState GetWaitState() const; | |
104 | |
105 // Returns the deadline for the call to MojoWaitMany(). | 100 // Returns the deadline for the call to MojoWaitMany(). |
106 MojoDeadline GetDeadlineForWait(const RunState& run_state) const; | 101 MojoDeadline GetDeadlineForWait(const RunState& run_state) const; |
107 | 102 |
| 103 void SignalHandleReady(Handle handle); |
| 104 |
108 void WillSignalHandler(); | 105 void WillSignalHandler(); |
109 void DidSignalHandler(); | 106 void DidSignalHandler(); |
110 | 107 |
111 // If non-NULL we're running (inside Run()). Member is reference to value on | 108 // If non-NULL we're running (inside Run()). Member is reference to value on |
112 // stack. | 109 // stack. |
113 RunState* run_state_; | 110 RunState* run_state_; |
114 | 111 |
115 // Lock for accessing |run_state_|. In general the only method that we have to | 112 // Lock for accessing |run_state_|. In general the only method that we have to |
116 // worry about is ScheduleWork(). All other methods are invoked on the same | 113 // worry about is ScheduleWork(). All other methods are invoked on the same |
117 // thread. | 114 // thread. |
118 base::Lock run_state_lock_; | 115 base::Lock run_state_lock_; |
119 | 116 |
120 HandleToHandler handlers_; | 117 HandleToHandler handlers_; |
121 // Set of handles that have a deadline set. Avoids iterating over all elements | 118 // Set of handles that have a deadline set. Avoids iterating over all elements |
122 // in |handles_| in the common case (no deadline set). | 119 // in |handles_| in the common case (no deadline set). |
123 // TODO(amistry): Make this better and avoid special-casing deadlines. | 120 // TODO(amistry): Make this better and avoid special-casing deadlines. |
124 std::set<Handle> deadline_handles_; | 121 std::set<Handle> deadline_handles_; |
125 | 122 |
126 // An ever increasing value assigned to each Handler::id. Used to detect | 123 // An ever increasing value assigned to each Handler::id. Used to detect |
127 // uniqueness while notifying. That is, while notifying expired timers we copy | 124 // uniqueness while notifying. That is, while notifying expired timers we copy |
128 // |handlers_| and only notify handlers whose id match. If the id does not | 125 // |handlers_| and only notify handlers whose id match. If the id does not |
129 // match it means the handler was removed then added so that we shouldn't | 126 // match it means the handler was removed then added so that we shouldn't |
130 // notify it. | 127 // notify it. |
131 int next_handler_id_; | 128 int next_handler_id_; |
132 | 129 |
133 base::ObserverList<Observer> observers_; | 130 base::ObserverList<Observer> observers_; |
134 | 131 |
| 132 // Mojo handle for the wait set. |
| 133 ScopedHandle wait_set_handle_; |
135 // Used to wake up run loop from |SignalControlPipe()|. | 134 // Used to wake up run loop from |SignalControlPipe()|. |
136 ScopedMessagePipeHandle read_handle_; | 135 ScopedMessagePipeHandle read_handle_; |
137 ScopedMessagePipeHandle write_handle_; | 136 ScopedMessagePipeHandle write_handle_; |
138 | 137 |
139 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); | 138 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); |
140 }; | 139 }; |
141 | 140 |
142 } // namespace common | 141 } // namespace common |
143 } // namespace mojo | 142 } // namespace mojo |
144 | 143 |
145 #endif // MOJO_MESSAGE_PUMP_MESSAGE_PUMP_MOJO_H_ | 144 #endif // MOJO_MESSAGE_PUMP_MESSAGE_PUMP_MOJO_H_ |
OLD | NEW |