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

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

Issue 3006933002: Allow PostTask() to take unique_ptr to classes derived of QueuedTask (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 | « no previous file | no next file » | 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) 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 #include "webrtc/rtc_base/scoped_ref_ptr.h"
25 #include "webrtc/rtc_base/type_traits.h"
kwiberg-webrtc 2017/08/31 10:45:33 You should #include <type_traits> instead.
eladalon 2017/08/31 10:51:04 Done.
25 26
26 #if defined(WEBRTC_WIN) 27 #if defined(WEBRTC_WIN)
27 #include "webrtc/rtc_base/platform_thread.h" 28 #include "webrtc/rtc_base/platform_thread.h"
28 #endif 29 #endif
29 30
30 namespace rtc { 31 namespace rtc {
31 32
32 // Base interface for asynchronously executed tasks. 33 // Base interface for asynchronously executed tasks.
33 // The interface basically consists of a single function, Run(), that executes 34 // The interface basically consists of a single function, Run(), that executes
34 // on the target queue. For more details see the Run() method and TaskQueue. 35 // on the target queue. For more details see the Run() method and TaskQueue.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
nisse-webrtc 2017/08/31 09:40:39 One question: At some point, we'll move to C++17,
kwiberg-webrtc 2017/08/31 10:45:33 Yes. (But it's C++14, not 17.)
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);
203 } 209 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698