Reduces unnecessary thread wakeups in TaskQueuePacedSender.

This CL is functionally a noop but may reduce thread wakupes in some
cases.

In particular, consider a send task scheduled for time T. While waiting
for that, a higher-priority packet than the top of the current queue is
added (e.g. an audio packet), and a send is executed immediately.

After sending, it resets the field indicating that a scheduled task is
expected at time T. It then polls NextSendTime() and schedules a new
task, likely at or very close to T. Causing unnecessary task queue
churn and behavior that is more difficult to reason about.

Bug: webrtc:10809
Change-Id: Ic5706f2cc06df3f27cc3e7b473d4de29a669473b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173700
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31116}
This commit is contained in:
Erik Språng 2020-04-19 11:05:41 +02:00 committed by Commit Bot
parent 811efc06df
commit f2b06ce5c8

View File

@ -188,12 +188,15 @@ void TaskQueuePacedSender::MaybeProcessPackets(
// anyway and clear any schedule.
Timestamp next_process_time = pacing_controller_.NextSendTime();
const Timestamp now = clock_->CurrentTime();
if ((scheduled_process_time.IsFinite() &&
scheduled_process_time == next_process_time_) ||
const bool is_scheduled_call = next_process_time_ == scheduled_process_time;
if (is_scheduled_call) {
// Indicate no pending scheduled call.
next_process_time_ = Timestamp::MinusInfinity();
}
if (is_scheduled_call ||
(now >= next_process_time && (next_process_time_.IsInfinite() ||
next_process_time < next_process_time_))) {
pacing_controller_.ProcessPackets();
next_process_time_ = Timestamp::MinusInfinity();
next_process_time = pacing_controller_.NextSendTime();
}