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

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

Issue 2706923005: Showing alternative approach to fixing TaskQueue deadlock. (Closed)
Patch Set: 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_libevent.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"
30 struct event_base; 32 struct event_base;
31 struct event; 33 struct event;
32 #endif 34 #endif
33 35
34 namespace rtc { 36 namespace rtc {
35 37
36 // Base interface for asynchronously executed tasks. 38 // Base interface for asynchronously executed tasks.
37 // The interface basically consists of a single function, Run(), that executes 39 // 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. 40 // on the target queue. For more details see the Run() method and TaskQueue.
39 class QueuedTask { 41 class QueuedTask {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 233 }
232 234
233 private: 235 private:
234 #if defined(WEBRTC_BUILD_LIBEVENT) 236 #if defined(WEBRTC_BUILD_LIBEVENT)
235 static bool ThreadMain(void* context); 237 static bool ThreadMain(void* context);
236 static void OnWakeup(int socket, short flags, void* context); // NOLINT 238 static void OnWakeup(int socket, short flags, void* context); // NOLINT
237 static void RunTask(int fd, short flags, void* context); // NOLINT 239 static void RunTask(int fd, short flags, void* context); // NOLINT
238 static void RunTimer(int fd, short flags, void* context); // NOLINT 240 static void RunTimer(int fd, short flags, void* context); // NOLINT
239 241
240 class PostAndReplyTask; 242 class PostAndReplyTask;
243 class PostAndReplyTaskRefOwner;
241 class SetTimerTask; 244 class SetTimerTask;
245 typedef RefCountedObject<PostAndReplyTask> PostAndReplyTaskRef;
242 246
243 void PrepareReplyTask(PostAndReplyTask* reply_task); 247 void PrepareReplyTask(scoped_refptr<PostAndReplyTaskRef> reply_task);
244 void ReplyTaskDone(PostAndReplyTask* reply_task); 248 void PostAndReplyTaskDone(PostAndReplyTask* reply_task);
245 249
246 struct QueueContext; 250 struct QueueContext;
247 251
248 int wakeup_pipe_in_ = -1; 252 int wakeup_pipe_in_ = -1;
249 int wakeup_pipe_out_ = -1; 253 int wakeup_pipe_out_ = -1;
250 event_base* event_base_; 254 event_base* event_base_;
251 std::unique_ptr<event> wakeup_event_; 255 std::unique_ptr<event> wakeup_event_;
252 PlatformThread thread_; 256 PlatformThread thread_;
253 rtc::CriticalSection pending_lock_; 257 rtc::CriticalSection pending_lock_;
254 std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_); 258 std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_);
255 std::list<PostAndReplyTask*> pending_replies_ GUARDED_BY(pending_lock_); 259 std::list<scoped_refptr<PostAndReplyTaskRef>> pending_replies_
260 GUARDED_BY(pending_lock_);
261 volatile bool destroying_ = false;
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_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698