Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: ipc/ipc_sync_channel.h

Issue 2077653002: Revert IPC SyncChannel to base::WaitableEvent waiting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ipc/ipc_sync_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 IPC_IPC_SYNC_CHANNEL_H_ 5 #ifndef IPC_IPC_SYNC_CHANNEL_H_
6 #define IPC_IPC_SYNC_CHANNEL_H_ 6 #define IPC_IPC_SYNC_CHANNEL_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/synchronization/waitable_event_watcher.h" 16 #include "base/synchronization/waitable_event_watcher.h"
17 #include "ipc/ipc_channel_handle.h" 17 #include "ipc/ipc_channel_handle.h"
18 #include "ipc/ipc_channel_proxy.h" 18 #include "ipc/ipc_channel_proxy.h"
19 #include "ipc/ipc_sync_message.h" 19 #include "ipc/ipc_sync_message.h"
20 #include "ipc/ipc_sync_message_filter.h" 20 #include "ipc/ipc_sync_message_filter.h"
21 #include "mojo/public/c/system/types.h"
22 #include "mojo/public/cpp/system/watcher.h"
23 21
24 namespace base { 22 namespace base {
25 class WaitableEvent; 23 class WaitableEvent;
26 }; 24 };
27 25
28 namespace mojo {
29 class Watcher;
30 }
31
32 namespace IPC { 26 namespace IPC {
33 27
28 class SyncMessage;
34 class ChannelFactory; 29 class ChannelFactory;
35 class MojoEvent;
36 class SyncMessage;
37 30
38 // This is similar to ChannelProxy, with the added feature of supporting sending 31 // This is similar to ChannelProxy, with the added feature of supporting sending
39 // synchronous messages. 32 // synchronous messages.
40 // 33 //
41 // Overview of how the sync channel works 34 // Overview of how the sync channel works
42 // -------------------------------------- 35 // --------------------------------------
43 // When the sending thread sends a synchronous message, we create a bunch 36 // When the sending thread sends a synchronous message, we create a bunch
44 // of tracking info (created in Send, stored in the PendingSyncMsg 37 // of tracking info (created in Send, stored in the PendingSyncMsg
45 // structure) associated with the message that we identify by the unique 38 // structure) associated with the message that we identify by the unique
46 // "MessageId" on the SyncMessage. Among the things we save is the 39 // "MessageId" on the SyncMessage. Among the things we save is the
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 base::WaitableEvent* shutdown_event); 135 base::WaitableEvent* shutdown_event);
143 136
144 // Adds information about an outgoing sync message to the context so that 137 // Adds information about an outgoing sync message to the context so that
145 // we know how to deserialize the reply. 138 // we know how to deserialize the reply.
146 void Push(SyncMessage* sync_msg); 139 void Push(SyncMessage* sync_msg);
147 140
148 // Cleanly remove the top deserializer (and throw it away). Returns the 141 // Cleanly remove the top deserializer (and throw it away). Returns the
149 // result of the Send call for that message. 142 // result of the Send call for that message.
150 bool Pop(); 143 bool Pop();
151 144
152 // Returns a Mojo Event that signals when a sync send is complete or timed 145 // Returns an event that's set when the send is complete, timed out or the
153 // out or the process shut down. 146 // process shut down.
154 MojoEvent* GetSendDoneEvent(); 147 base::WaitableEvent* GetSendDoneEvent();
155 148
156 // Returns a Mojo Event that signals when an incoming message that's not the 149 // Returns an event that's set when an incoming message that's not the reply
157 // pending reply needs to get dispatched (by calling DispatchMessages.) 150 // needs to get dispatched (by calling SyncContext::DispatchMessages).
158 MojoEvent* GetDispatchEvent(); 151 base::WaitableEvent* GetDispatchEvent();
159 152
160 void DispatchMessages(); 153 void DispatchMessages();
161 154
162 // Checks if the given message is blocking the listener thread because of a 155 // Checks if the given message is blocking the listener thread because of a
163 // synchronous send. If it is, the thread is unblocked and true is 156 // synchronous send. If it is, the thread is unblocked and true is
164 // returned. Otherwise the function returns false. 157 // returned. Otherwise the function returns false.
165 bool TryToUnblockListener(const Message* msg); 158 bool TryToUnblockListener(const Message* msg);
166 159
167 base::WaitableEvent* shutdown_event() { return shutdown_event_; } 160 base::WaitableEvent* shutdown_event() { return shutdown_event_; }
168 161
169 ReceivedSyncMsgQueue* received_sync_msgs() { 162 ReceivedSyncMsgQueue* received_sync_msgs() {
170 return received_sync_msgs_.get(); 163 return received_sync_msgs_.get();
171 } 164 }
172 165
173 void set_restrict_dispatch_group(int group) { 166 void set_restrict_dispatch_group(int group) {
174 restrict_dispatch_group_ = group; 167 restrict_dispatch_group_ = group;
175 } 168 }
176 169
177 int restrict_dispatch_group() const { 170 int restrict_dispatch_group() const {
178 return restrict_dispatch_group_; 171 return restrict_dispatch_group_;
179 } 172 }
180 173
174 base::WaitableEventWatcher::EventCallback MakeWaitableEventCallback();
175
181 private: 176 private:
182 ~SyncContext() override; 177 ~SyncContext() override;
183 // ChannelProxy methods that we override. 178 // ChannelProxy methods that we override.
184 179
185 // Called on the listener thread. 180 // Called on the listener thread.
186 void Clear() override; 181 void Clear() override;
187 182
188 // Called on the IPC thread. 183 // Called on the IPC thread.
189 bool OnMessageReceived(const Message& msg) override; 184 bool OnMessageReceived(const Message& msg) override;
190 void OnChannelError() override; 185 void OnChannelError() override;
191 void OnChannelOpened() override; 186 void OnChannelOpened() override;
192 void OnChannelClosed() override; 187 void OnChannelClosed() override;
193 188
194 // Cancels all pending Send calls. 189 // Cancels all pending Send calls.
195 void CancelPendingSends(); 190 void CancelPendingSends();
196 191
197 void OnShutdownEventSignaled(base::WaitableEvent* event); 192 void OnWaitableEventSignaled(base::WaitableEvent* event);
198 193
199 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; 194 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue;
200 PendingSyncMessageQueue deserializers_; 195 PendingSyncMessageQueue deserializers_;
201 base::Lock deserializers_lock_; 196 base::Lock deserializers_lock_;
202 197
203 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; 198 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_;
204 199
205 base::WaitableEvent* shutdown_event_; 200 base::WaitableEvent* shutdown_event_;
206 base::WaitableEventWatcher shutdown_watcher_; 201 base::WaitableEventWatcher shutdown_watcher_;
207 base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_; 202 base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_;
208 int restrict_dispatch_group_; 203 int restrict_dispatch_group_;
209 }; 204 };
210 205
211 private: 206 private:
212 SyncChannel( 207 SyncChannel(
213 Listener* listener, 208 Listener* listener,
214 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, 209 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
215 base::WaitableEvent* shutdown_event); 210 base::WaitableEvent* shutdown_event);
216 211
217 void OnDispatchHandleReady(MojoResult result); 212 void OnWaitableEventSignaled(base::WaitableEvent* arg);
218 213
219 SyncContext* sync_context() { 214 SyncContext* sync_context() {
220 return reinterpret_cast<SyncContext*>(context()); 215 return reinterpret_cast<SyncContext*>(context());
221 } 216 }
222 217
223 // Both these functions wait for a reply, timeout or process shutdown. The 218 // Both these functions wait for a reply, timeout or process shutdown. The
224 // latter one also runs a nested message loop in the meantime. 219 // latter one also runs a nested message loop in the meantime.
225 static void WaitForReply(SyncContext* context, bool pump_messages); 220 static void WaitForReply(
221 SyncContext* context, base::WaitableEvent* pump_messages_event);
226 222
227 // Runs a nested message loop until a reply arrives, times out, or the process 223 // Runs a nested message loop until a reply arrives, times out, or the process
228 // shuts down. 224 // shuts down.
229 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); 225 static void WaitForReplyWithNestedMessageLoop(SyncContext* context);
230 226
231 // Starts the dispatch watcher. 227 // Starts the dispatch watcher.
232 void StartWatching(); 228 void StartWatching();
233 229
234 // ChannelProxy overrides: 230 // ChannelProxy overrides:
235 void OnChannelInit() override; 231 void OnChannelInit() override;
236 232
237 // Used to signal events between the IPC and listener threads. 233 // Used to signal events between the IPC and listener threads.
238 mojo::Watcher dispatch_watcher_; 234 base::WaitableEventWatcher dispatch_watcher_;
235 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_;
239 236
240 // Tracks SyncMessageFilters created before complete channel initialization. 237 // Tracks SyncMessageFilters created before complete channel initialization.
241 std::vector<scoped_refptr<SyncMessageFilter>> pre_init_sync_message_filters_; 238 std::vector<scoped_refptr<SyncMessageFilter>> pre_init_sync_message_filters_;
242 239
243 DISALLOW_COPY_AND_ASSIGN(SyncChannel); 240 DISALLOW_COPY_AND_ASSIGN(SyncChannel);
244 }; 241 };
245 242
246 } // namespace IPC 243 } // namespace IPC
247 244
248 #endif // IPC_IPC_SYNC_CHANNEL_H_ 245 #endif // IPC_IPC_SYNC_CHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc_sync_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698