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 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // TODO(tommi): For better debuggability, implement RTC_FROM_HERE. | 171 // TODO(tommi): For better debuggability, implement RTC_FROM_HERE. |
172 | 172 |
173 // Ownership of the task is passed to PostTask. | 173 // Ownership of the task is passed to PostTask. |
174 void PostTask(std::unique_ptr<QueuedTask> task); | 174 void PostTask(std::unique_ptr<QueuedTask> task); |
175 void PostTaskAndReply(std::unique_ptr<QueuedTask> task, | 175 void PostTaskAndReply(std::unique_ptr<QueuedTask> task, |
176 std::unique_ptr<QueuedTask> reply, | 176 std::unique_ptr<QueuedTask> reply, |
177 TaskQueue* reply_queue); | 177 TaskQueue* reply_queue); |
178 void PostTaskAndReply(std::unique_ptr<QueuedTask> task, | 178 void PostTaskAndReply(std::unique_ptr<QueuedTask> task, |
179 std::unique_ptr<QueuedTask> reply); | 179 std::unique_ptr<QueuedTask> reply); |
180 | 180 |
| 181 // Schedules a task to execute a specified number of milliseconds from when |
| 182 // the call is made. The precision should be considered as "best effort" |
| 183 // and in some cases, such as on Windows when all high precision timers have |
| 184 // been used up, can be off by as much as 15 millseconds (although 8 would be |
| 185 // more likely). This can be mitigated by limiting the use of delayed tasks. |
181 void PostDelayedTask(std::unique_ptr<QueuedTask> task, uint32_t milliseconds); | 186 void PostDelayedTask(std::unique_ptr<QueuedTask> task, uint32_t milliseconds); |
182 | 187 |
183 template <class Closure> | 188 template <class Closure> |
184 void PostTask(const Closure& closure) { | 189 void PostTask(const Closure& closure) { |
185 PostTask(std::unique_ptr<QueuedTask>(new ClosureTask<Closure>(closure))); | 190 PostTask(std::unique_ptr<QueuedTask>(new ClosureTask<Closure>(closure))); |
186 } | 191 } |
187 | 192 |
| 193 // See documentation above for performance expectations. |
188 template <class Closure> | 194 template <class Closure> |
189 void PostDelayedTask(const Closure& closure, uint32_t milliseconds) { | 195 void PostDelayedTask(const Closure& closure, uint32_t milliseconds) { |
190 PostDelayedTask( | 196 PostDelayedTask( |
191 std::unique_ptr<QueuedTask>(new ClosureTask<Closure>(closure)), | 197 std::unique_ptr<QueuedTask>(new ClosureTask<Closure>(closure)), |
192 milliseconds); | 198 milliseconds); |
193 } | 199 } |
194 | 200 |
195 template <class Closure1, class Closure2> | 201 template <class Closure1, class Closure2> |
196 void PostTaskAndReply(const Closure1& task, | 202 void PostTaskAndReply(const Closure1& task, |
197 const Closure2& reply, | 203 const Closure2& reply, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 rtc::CriticalSection pending_lock_; | 253 rtc::CriticalSection pending_lock_; |
248 std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_); | 254 std::list<std::unique_ptr<QueuedTask>> pending_ GUARDED_BY(pending_lock_); |
249 std::list<PostAndReplyTask*> pending_replies_ GUARDED_BY(pending_lock_); | 255 std::list<PostAndReplyTask*> pending_replies_ GUARDED_BY(pending_lock_); |
250 #elif defined(WEBRTC_MAC) | 256 #elif defined(WEBRTC_MAC) |
251 struct QueueContext; | 257 struct QueueContext; |
252 struct TaskContext; | 258 struct TaskContext; |
253 struct PostTaskAndReplyContext; | 259 struct PostTaskAndReplyContext; |
254 dispatch_queue_t queue_; | 260 dispatch_queue_t queue_; |
255 QueueContext* const context_; | 261 QueueContext* const context_; |
256 #elif defined(WEBRTC_WIN) | 262 #elif defined(WEBRTC_WIN) |
| 263 class MultimediaTimer; |
257 typedef std::unordered_map<UINT_PTR, std::unique_ptr<QueuedTask>> | 264 typedef std::unordered_map<UINT_PTR, std::unique_ptr<QueuedTask>> |
258 DelayedTasks; | 265 DelayedTasks; |
259 static bool ThreadMain(void* context); | 266 static bool ThreadMain(void* context); |
260 static bool ProcessQueuedMessages(DelayedTasks* delayed_tasks); | 267 static bool ProcessQueuedMessages(DelayedTasks* delayed_tasks, |
| 268 std::vector<MultimediaTimer>* timers); |
261 | 269 |
262 class WorkerThread : public PlatformThread { | 270 class WorkerThread : public PlatformThread { |
263 public: | 271 public: |
264 WorkerThread(ThreadRunFunction func, void* obj, const char* thread_name) | 272 WorkerThread(ThreadRunFunction func, void* obj, const char* thread_name) |
265 : PlatformThread(func, obj, thread_name) {} | 273 : PlatformThread(func, obj, thread_name) {} |
266 | 274 |
267 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data) { | 275 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data) { |
268 return PlatformThread::QueueAPC(apc_function, data); | 276 return PlatformThread::QueueAPC(apc_function, data); |
269 } | 277 } |
270 }; | 278 }; |
271 WorkerThread thread_; | 279 WorkerThread thread_; |
272 #else | 280 #else |
273 #error not supported. | 281 #error not supported. |
274 #endif | 282 #endif |
275 | 283 |
276 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 284 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
277 }; | 285 }; |
278 | 286 |
279 } // namespace rtc | 287 } // namespace rtc |
280 | 288 |
281 #endif // WEBRTC_BASE_TASK_QUEUE_H_ | 289 #endif // WEBRTC_BASE_TASK_QUEUE_H_ |
OLD | NEW |