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 | 18 |
18 #if defined(WEBRTC_MAC) | 19 #if defined(WEBRTC_MAC) |
19 #include <dispatch/dispatch.h> | 20 #include <dispatch/dispatch.h> |
20 #endif | 21 #endif |
21 | 22 |
22 #include "webrtc/rtc_base/constructormagic.h" | 23 #include "webrtc/rtc_base/constructormagic.h" |
23 #include "webrtc/rtc_base/criticalsection.h" | 24 #include "webrtc/rtc_base/criticalsection.h" |
24 #include "webrtc/rtc_base/scoped_ref_ptr.h" | 25 #include "webrtc/rtc_base/scoped_ref_ptr.h" |
25 | 26 |
26 #if defined(WEBRTC_WIN) | 27 #if defined(WEBRTC_WIN) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 void PostTaskAndReply(std::unique_ptr<QueuedTask> task, | 183 void PostTaskAndReply(std::unique_ptr<QueuedTask> task, |
183 std::unique_ptr<QueuedTask> reply); | 184 std::unique_ptr<QueuedTask> reply); |
184 | 185 |
185 // Schedules a task to execute a specified number of milliseconds from when | 186 // Schedules a task to execute a specified number of milliseconds from when |
186 // the call is made. The precision should be considered as "best effort" | 187 // the call is made. The precision should be considered as "best effort" |
187 // and in some cases, such as on Windows when all high precision timers have | 188 // and in some cases, such as on Windows when all high precision timers have |
188 // been used up, can be off by as much as 15 millseconds (although 8 would be | 189 // been used up, can be off by as much as 15 millseconds (although 8 would be |
189 // more likely). This can be mitigated by limiting the use of delayed tasks. | 190 // more likely). This can be mitigated by limiting the use of delayed tasks. |
190 void PostDelayedTask(std::unique_ptr<QueuedTask> task, uint32_t milliseconds); | 191 void PostDelayedTask(std::unique_ptr<QueuedTask> task, uint32_t milliseconds); |
191 | 192 |
192 template <class Closure> | 193 // std::enable_if is used here to make sure that calls to PostTask() with |
| 194 // std::unique_ptr<SomeClassDerivedFromQueuedTask> would not end up being |
| 195 // caught by this template. |
| 196 template <class Closure, |
| 197 typename std::enable_if< |
| 198 std::is_copy_constructible<Closure>::value>::type* = nullptr> |
193 void PostTask(const Closure& closure) { | 199 void PostTask(const Closure& closure) { |
194 PostTask(std::unique_ptr<QueuedTask>(new ClosureTask<Closure>(closure))); | 200 PostTask(std::unique_ptr<QueuedTask>(new ClosureTask<Closure>(closure))); |
195 } | 201 } |
196 | 202 |
197 // See documentation above for performance expectations. | 203 // See documentation above for performance expectations. |
198 template <class Closure> | 204 template <class Closure> |
199 void PostDelayedTask(const Closure& closure, uint32_t milliseconds) { | 205 void PostDelayedTask(const Closure& closure, uint32_t milliseconds) { |
200 PostDelayedTask( | 206 PostDelayedTask( |
201 std::unique_ptr<QueuedTask>(new ClosureTask<Closure>(closure)), | 207 std::unique_ptr<QueuedTask>(new ClosureTask<Closure>(closure)), |
202 milliseconds); | 208 milliseconds); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 class Impl; | 272 class Impl; |
267 const scoped_refptr<Impl> impl_; | 273 const scoped_refptr<Impl> impl_; |
268 #endif | 274 #endif |
269 | 275 |
270 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 276 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
271 }; | 277 }; |
272 | 278 |
273 } // namespace rtc | 279 } // namespace rtc |
274 | 280 |
275 #endif // WEBRTC_RTC_BASE_TASK_QUEUE_H_ | 281 #endif // WEBRTC_RTC_BASE_TASK_QUEUE_H_ |
OLD | NEW |