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

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

Issue 3003643002: Allow external TaskQueue implementations on Linux (Closed)
Patch Set: .. Created 3 years, 3 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 | « webrtc/rtc_base/BUILD.gn ('k') | webrtc/rtc_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_RTC_BASE_TASK_QUEUE_H_ 11 #ifndef WEBRTC_RTC_BASE_TASK_QUEUE_H_
12 #define WEBRTC_RTC_BASE_TASK_QUEUE_H_ 12 #define WEBRTC_RTC_BASE_TASK_QUEUE_H_
13 13
14 #include <list> 14 #include <list>
15 #include <memory> 15 #include <memory>
16 #include <queue> 16 #include <queue>
17 17
18 #if defined(WEBRTC_MAC) && !defined(WEBRTC_BUILD_LIBEVENT) 18 #if defined(WEBRTC_MAC)
19 #include <dispatch/dispatch.h> 19 #include <dispatch/dispatch.h>
20 #endif 20 #endif
21 21
22 #include "webrtc/rtc_base/constructormagic.h" 22 #include "webrtc/rtc_base/constructormagic.h"
23 #include "webrtc/rtc_base/criticalsection.h" 23 #include "webrtc/rtc_base/criticalsection.h"
24 #include "webrtc/rtc_base/scoped_ref_ptr.h"
24 25
25 #if defined(WEBRTC_WIN) || defined(WEBRTC_BUILD_LIBEVENT) 26 #if defined(WEBRTC_WIN)
26 #include "webrtc/rtc_base/platform_thread.h" 27 #include "webrtc/rtc_base/platform_thread.h"
27 #endif 28 #endif
28 29
29 #if defined(WEBRTC_BUILD_LIBEVENT)
30 #include "webrtc/rtc_base/refcountedobject.h"
31 #include "webrtc/rtc_base/scoped_ref_ptr.h"
32
33 struct event_base;
34 struct event;
35 #endif
36
37 namespace rtc { 30 namespace rtc {
38 31
39 // Base interface for asynchronously executed tasks. 32 // Base interface for asynchronously executed tasks.
40 // The interface basically consists of a single function, Run(), that executes 33 // The interface basically consists of a single function, Run(), that executes
41 // on the target queue. For more details see the Run() method and TaskQueue. 34 // on the target queue. For more details see the Run() method and TaskQueue.
42 class QueuedTask { 35 class QueuedTask {
43 public: 36 public:
44 QueuedTask() {} 37 QueuedTask() {}
45 virtual ~QueuedTask() {} 38 virtual ~QueuedTask() {}
46 39
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 228 }
236 229
237 template <class Closure1, class Closure2> 230 template <class Closure1, class Closure2>
238 void PostTaskAndReply(const Closure1& task, const Closure2& reply) { 231 void PostTaskAndReply(const Closure1& task, const Closure2& reply) {
239 PostTaskAndReply( 232 PostTaskAndReply(
240 std::unique_ptr<QueuedTask>(new ClosureTask<Closure1>(task)), 233 std::unique_ptr<QueuedTask>(new ClosureTask<Closure1>(task)),
241 std::unique_ptr<QueuedTask>(new ClosureTask<Closure2>(reply))); 234 std::unique_ptr<QueuedTask>(new ClosureTask<Closure2>(reply)));
242 } 235 }
243 236
244 private: 237 private:
245 #if defined(WEBRTC_BUILD_LIBEVENT) 238 #if defined(WEBRTC_MAC)
246 static void ThreadMain(void* context);
247 static void OnWakeup(int socket, short flags, void* context); // NOLINT
248 static void RunTask(int fd, short flags, void* context); // NOLINT
249 static void RunTimer(int fd, short flags, void* context); // NOLINT
250
251 class ReplyTaskOwner;
252 class PostAndReplyTask;
253 class SetTimerTask;
254
255 typedef RefCountedObject<ReplyTaskOwner> ReplyTaskOwnerRef;
256
257 void PrepareReplyTask(scoped_refptr<ReplyTaskOwnerRef> reply_task);
258
259 struct QueueContext;
260
261 int wakeup_pipe_in_ = -1;
262 int wakeup_pipe_out_ = -1;
263 event_base* event_base_;
264 std::unique_ptr<event> wakeup_event_;
265 PlatformThread thread_;
266 rtc::CriticalSection pending_lock_;
267 std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_);
268 std::list<scoped_refptr<ReplyTaskOwnerRef>> pending_replies_
269 GUARDED_BY(pending_lock_);
270 #elif defined(WEBRTC_MAC)
271 struct QueueContext; 239 struct QueueContext;
272 struct TaskContext; 240 struct TaskContext;
273 struct PostTaskAndReplyContext; 241 struct PostTaskAndReplyContext;
274 dispatch_queue_t queue_; 242 dispatch_queue_t queue_;
275 QueueContext* const context_; 243 QueueContext* const context_;
276 #elif defined(WEBRTC_WIN) 244 #elif defined(WEBRTC_WIN)
277 class ThreadState; 245 class ThreadState;
278 void RunPendingTasks(); 246 void RunPendingTasks();
279 static void ThreadMain(void* context); 247 static void ThreadMain(void* context);
280 248
281 class WorkerThread : public PlatformThread { 249 class WorkerThread : public PlatformThread {
282 public: 250 public:
283 WorkerThread(ThreadRunFunction func, 251 WorkerThread(ThreadRunFunction func,
284 void* obj, 252 void* obj,
285 const char* thread_name, 253 const char* thread_name,
286 ThreadPriority priority) 254 ThreadPriority priority)
287 : PlatformThread(func, obj, thread_name, priority) {} 255 : PlatformThread(func, obj, thread_name, priority) {}
288 256
289 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data) { 257 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data) {
290 return PlatformThread::QueueAPC(apc_function, data); 258 return PlatformThread::QueueAPC(apc_function, data);
291 } 259 }
292 }; 260 };
293 WorkerThread thread_; 261 WorkerThread thread_;
294 rtc::CriticalSection pending_lock_; 262 rtc::CriticalSection pending_lock_;
295 std::queue<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_); 263 std::queue<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_);
296 HANDLE in_queue_; 264 HANDLE in_queue_;
297 #else 265 #else
298 #error not supported. 266 class Impl;
267 const scoped_refptr<Impl> impl_;
299 #endif 268 #endif
300 269
301 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); 270 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue);
302 }; 271 };
303 272
304 } // namespace rtc 273 } // namespace rtc
305 274
306 #endif // WEBRTC_RTC_BASE_TASK_QUEUE_H_ 275 #endif // WEBRTC_RTC_BASE_TASK_QUEUE_H_
OLDNEW
« no previous file with comments | « webrtc/rtc_base/BUILD.gn ('k') | webrtc/rtc_base/task_queue_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698