Always enter yield policy scope using simulated TimeControllers.

This makes the class easier to use at a minor cost of making it slightly
more magic.

Bug: webrtc:9883
Change-Id: If807cfbf046615333c3bcd3b58a001813102a9f9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161231
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Markus Handell <handellm@webrtc.org>
Commit-Queue: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30008}
This commit is contained in:
Sebastian Jansson
2019-12-04 10:07:48 +01:00
committed by Commit Bot
parent 242a9e0ffe
commit 340af975e9
10 changed files with 11 additions and 61 deletions

View File

@ -159,7 +159,9 @@ class ExternalTimeController::TaskQueueWrapper : public TaskQueueBase {
};
ExternalTimeController::ExternalTimeController(ControlledAlarmClock* alarm)
: alarm_(alarm), impl_(alarm_->GetClock()->CurrentTime()) {
: alarm_(alarm),
impl_(alarm_->GetClock()->CurrentTime()),
yield_policy_(&impl_) {
global_clock_.SetTime(alarm_->GetClock()->CurrentTime());
alarm_->SetCallback([this] { Run(); });
}
@ -182,16 +184,6 @@ void ExternalTimeController::AdvanceTime(TimeDelta duration) {
alarm_->Sleep(duration);
}
void ExternalTimeController::InvokeWithControlledYield(
std::function<void()> closure) {
rtc::ScopedYieldPolicy policy(YieldInterface());
closure();
}
rtc::YieldInterface* ExternalTimeController::YieldInterface() {
return &impl_;
}
std::unique_ptr<TaskQueueBase, TaskQueueDeleter>
ExternalTimeController::CreateTaskQueue(
absl::string_view name,