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

Side by Side Diff: webrtc/base/task_queue.h

Issue 2709603002: Fix potential deadlock in TaskQueue's libevent PostTaskAndReply implementation (Closed)
Patch Set: Address comments Created 3 years, 10 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 | webrtc/base/task_queue_gcd.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 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_TASK_QUEUE_H_ 11 #ifndef WEBRTC_BASE_TASK_QUEUE_H_
12 #define WEBRTC_BASE_TASK_QUEUE_H_ 12 #define WEBRTC_BASE_TASK_QUEUE_H_
13 13
14 #include <list> 14 #include <list>
15 #include <memory> 15 #include <memory>
16 #include <unordered_map> 16 #include <unordered_map>
17 17
18 #if defined(WEBRTC_MAC) && !defined(WEBRTC_BUILD_LIBEVENT) 18 #if defined(WEBRTC_MAC) && !defined(WEBRTC_BUILD_LIBEVENT)
19 #include <dispatch/dispatch.h> 19 #include <dispatch/dispatch.h>
20 #endif 20 #endif
21 21
22 #include "webrtc/base/constructormagic.h" 22 #include "webrtc/base/constructormagic.h"
23 #include "webrtc/base/criticalsection.h" 23 #include "webrtc/base/criticalsection.h"
24 24
25 #if defined(WEBRTC_WIN) || defined(WEBRTC_BUILD_LIBEVENT) 25 #if defined(WEBRTC_WIN) || defined(WEBRTC_BUILD_LIBEVENT)
26 #include "webrtc/base/platform_thread.h" 26 #include "webrtc/base/platform_thread.h"
27 #endif 27 #endif
28 28
29 #if defined(WEBRTC_BUILD_LIBEVENT) 29 #if defined(WEBRTC_BUILD_LIBEVENT)
30 #include "webrtc/base/refcountedobject.h"
31 #include "webrtc/base/scoped_ref_ptr.h"
32
30 struct event_base; 33 struct event_base;
31 struct event; 34 struct event;
32 #endif 35 #endif
33 36
34 namespace rtc { 37 namespace rtc {
35 38
36 // Base interface for asynchronously executed tasks. 39 // Base interface for asynchronously executed tasks.
37 // The interface basically consists of a single function, Run(), that executes 40 // The interface basically consists of a single function, Run(), that executes
38 // on the target queue. For more details see the Run() method and TaskQueue. 41 // on the target queue. For more details see the Run() method and TaskQueue.
39 class QueuedTask { 42 class QueuedTask {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 std::unique_ptr<QueuedTask>(new ClosureTask<Closure2>(reply))); 233 std::unique_ptr<QueuedTask>(new ClosureTask<Closure2>(reply)));
231 } 234 }
232 235
233 private: 236 private:
234 #if defined(WEBRTC_BUILD_LIBEVENT) 237 #if defined(WEBRTC_BUILD_LIBEVENT)
235 static bool ThreadMain(void* context); 238 static bool ThreadMain(void* context);
236 static void OnWakeup(int socket, short flags, void* context); // NOLINT 239 static void OnWakeup(int socket, short flags, void* context); // NOLINT
237 static void RunTask(int fd, short flags, void* context); // NOLINT 240 static void RunTask(int fd, short flags, void* context); // NOLINT
238 static void RunTimer(int fd, short flags, void* context); // NOLINT 241 static void RunTimer(int fd, short flags, void* context); // NOLINT
239 242
243 class ReplyTaskOwner;
240 class PostAndReplyTask; 244 class PostAndReplyTask;
241 class SetTimerTask; 245 class SetTimerTask;
242 246
243 void PrepareReplyTask(PostAndReplyTask* reply_task); 247 typedef RefCountedObject<ReplyTaskOwner> ReplyTaskOwnerRef;
244 void ReplyTaskDone(PostAndReplyTask* reply_task); 248
249 void PrepareReplyTask(scoped_refptr<ReplyTaskOwnerRef> reply_task);
245 250
246 struct QueueContext; 251 struct QueueContext;
247 252
248 int wakeup_pipe_in_ = -1; 253 int wakeup_pipe_in_ = -1;
249 int wakeup_pipe_out_ = -1; 254 int wakeup_pipe_out_ = -1;
250 event_base* event_base_; 255 event_base* event_base_;
251 std::unique_ptr<event> wakeup_event_; 256 std::unique_ptr<event> wakeup_event_;
252 PlatformThread thread_; 257 PlatformThread thread_;
253 rtc::CriticalSection pending_lock_; 258 rtc::CriticalSection pending_lock_;
254 std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_); 259 std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_);
255 std::list<PostAndReplyTask*> pending_replies_ GUARDED_BY(pending_lock_); 260 std::list<scoped_refptr<ReplyTaskOwnerRef>> pending_replies_
261 GUARDED_BY(pending_lock_);
256 #elif defined(WEBRTC_MAC) 262 #elif defined(WEBRTC_MAC)
257 struct QueueContext; 263 struct QueueContext;
258 struct TaskContext; 264 struct TaskContext;
259 struct PostTaskAndReplyContext; 265 struct PostTaskAndReplyContext;
260 dispatch_queue_t queue_; 266 dispatch_queue_t queue_;
261 QueueContext* const context_; 267 QueueContext* const context_;
262 #elif defined(WEBRTC_WIN) 268 #elif defined(WEBRTC_WIN)
263 class MultimediaTimer; 269 class MultimediaTimer;
264 typedef std::unordered_map<UINT_PTR, std::unique_ptr<QueuedTask>> 270 typedef std::unordered_map<UINT_PTR, std::unique_ptr<QueuedTask>>
265 DelayedTasks; 271 DelayedTasks;
(...skipping 14 matching lines...) Expand all
280 #else 286 #else
281 #error not supported. 287 #error not supported.
282 #endif 288 #endif
283 289
284 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); 290 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue);
285 }; 291 };
286 292
287 } // namespace rtc 293 } // namespace rtc
288 294
289 #endif // WEBRTC_BASE_TASK_QUEUE_H_ 295 #endif // WEBRTC_BASE_TASK_QUEUE_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/task_queue_gcd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698