| OLD | NEW |
| 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 #include <type_traits> | 17 #include <type_traits> |
| 18 | 18 |
| 19 #if defined(WEBRTC_MAC) | 19 #if defined(WEBRTC_MAC) |
| 20 #include <dispatch/dispatch.h> | 20 #include <dispatch/dispatch.h> |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #include "webrtc/rtc_base/constructormagic.h" | 23 #include "webrtc/rtc_base/constructormagic.h" |
| 24 #include "webrtc/rtc_base/criticalsection.h" | 24 #include "webrtc/rtc_base/criticalsection.h" |
| 25 #include "webrtc/rtc_base/scoped_ref_ptr.h" | 25 #include "webrtc/rtc_base/scoped_ref_ptr.h" |
| 26 | 26 |
| 27 #if defined(WEBRTC_WIN) | |
| 28 #include "webrtc/rtc_base/platform_thread.h" | |
| 29 #endif | |
| 30 | |
| 31 namespace rtc { | 27 namespace rtc { |
| 32 | 28 |
| 33 // Base interface for asynchronously executed tasks. | 29 // Base interface for asynchronously executed tasks. |
| 34 // The interface basically consists of a single function, Run(), that executes | 30 // The interface basically consists of a single function, Run(), that executes |
| 35 // on the target queue. For more details see the Run() method and TaskQueue. | 31 // on the target queue. For more details see the Run() method and TaskQueue. |
| 36 class QueuedTask { | 32 class QueuedTask { |
| 37 public: | 33 public: |
| 38 QueuedTask() {} | 34 QueuedTask() {} |
| 39 virtual ~QueuedTask() {} | 35 virtual ~QueuedTask() {} |
| 40 | 36 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 std::unique_ptr<QueuedTask>(new ClosureTask<Closure2>(reply))); | 235 std::unique_ptr<QueuedTask>(new ClosureTask<Closure2>(reply))); |
| 240 } | 236 } |
| 241 | 237 |
| 242 private: | 238 private: |
| 243 #if defined(WEBRTC_MAC) | 239 #if defined(WEBRTC_MAC) |
| 244 struct QueueContext; | 240 struct QueueContext; |
| 245 struct TaskContext; | 241 struct TaskContext; |
| 246 struct PostTaskAndReplyContext; | 242 struct PostTaskAndReplyContext; |
| 247 dispatch_queue_t queue_; | 243 dispatch_queue_t queue_; |
| 248 QueueContext* const context_; | 244 QueueContext* const context_; |
| 249 #elif defined(WEBRTC_WIN) | |
| 250 class ThreadState; | |
| 251 void RunPendingTasks(); | |
| 252 static void ThreadMain(void* context); | |
| 253 | |
| 254 class WorkerThread : public PlatformThread { | |
| 255 public: | |
| 256 WorkerThread(ThreadRunFunction func, | |
| 257 void* obj, | |
| 258 const char* thread_name, | |
| 259 ThreadPriority priority) | |
| 260 : PlatformThread(func, obj, thread_name, priority) {} | |
| 261 | |
| 262 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data) { | |
| 263 return PlatformThread::QueueAPC(apc_function, data); | |
| 264 } | |
| 265 }; | |
| 266 WorkerThread thread_; | |
| 267 rtc::CriticalSection pending_lock_; | |
| 268 std::queue<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_); | |
| 269 HANDLE in_queue_; | |
| 270 #else | 245 #else |
| 271 class Impl; | 246 class Impl; |
| 272 const scoped_refptr<Impl> impl_; | 247 const scoped_refptr<Impl> impl_; |
| 273 #endif | 248 #endif |
| 274 | 249 |
| 275 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 250 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
| 276 }; | 251 }; |
| 277 | 252 |
| 278 } // namespace rtc | 253 } // namespace rtc |
| 279 | 254 |
| 280 #endif // WEBRTC_RTC_BASE_TASK_QUEUE_H_ | 255 #endif // WEBRTC_RTC_BASE_TASK_QUEUE_H_ |
| OLD | NEW |