Make use of TaskQueue/TaskQueueBase's PostDelayedHighPrecisionTask.
Use cases of TaskQueue or TaskQueueBase that are considered high
precision are updated to make use of PostDelayedHighPrecisionTask
(see go/postdelayedtask-precision-in-webrtc) instead of PostDelayedTask.
The cases here are the ones covered by that document, plus some
testing-only uses. The FrameBuffer2 and DataTracker use cases will
be covered by separate CLs because FrameBuffer2 uses
RepeatingTaskHandle and DataTracker uses dcsctp::Timer.
This protects these use cases against regressions when PostDelayedTask
gets its precision lowered.
This CL also adds TaskQueue::PostDelayedHighPrecisionTask which calls
TaskQueueBase::PostDelayedHighPrecisionTask (same pattern as for
PostDelayedTask).
Bug: webrtc:13604
Change-Id: I7dcab59cbe4d274d27b734ceb4fc06daa12ffd0f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/248864
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35781}
diff --git a/rtc_base/task_queue.h b/rtc_base/task_queue.h
index 1798d06..4ad3fed 100644
--- a/rtc_base/task_queue.h
+++ b/rtc_base/task_queue.h
@@ -95,14 +95,11 @@
// Ownership of the task is passed to PostTask.
void PostTask(std::unique_ptr<webrtc::QueuedTask> task);
-
- // Schedules a task to execute a specified number of milliseconds from when
- // the call is made. The precision should be considered as "best effort"
- // and in some cases, such as on Windows when all high precision timers have
- // been used up, can be off by as much as 15 millseconds (although 8 would be
- // more likely). This can be mitigated by limiting the use of delayed tasks.
+ // See webrtc::TaskQueueBase for precision expectations.
void PostDelayedTask(std::unique_ptr<webrtc::QueuedTask> task,
uint32_t milliseconds);
+ void PostDelayedHighPrecisionTask(std::unique_ptr<webrtc::QueuedTask> task,
+ uint32_t milliseconds);
// std::enable_if is used here to make sure that calls to PostTask() with
// std::unique_ptr<SomeClassDerivedFromQueuedTask> would not end up being
@@ -114,8 +111,6 @@
void PostTask(Closure&& closure) {
PostTask(webrtc::ToQueuedTask(std::forward<Closure>(closure)));
}
-
- // See documentation above for performance expectations.
template <class Closure,
typename std::enable_if<!std::is_convertible<
Closure,
@@ -124,6 +119,14 @@
PostDelayedTask(webrtc::ToQueuedTask(std::forward<Closure>(closure)),
milliseconds);
}
+ template <class Closure,
+ typename std::enable_if<!std::is_convertible<
+ Closure,
+ std::unique_ptr<webrtc::QueuedTask>>::value>::type* = nullptr>
+ void PostDelayedHighPrecisionTask(Closure&& closure, uint32_t milliseconds) {
+ PostDelayedHighPrecisionTask(
+ webrtc::ToQueuedTask(std::forward<Closure>(closure)), milliseconds);
+ }
private:
webrtc::TaskQueueBase* const impl_;