Fix for recursive yield crash in simulated time controller.
Without this |ready_runners_| might still have entries left if the
yield call comes from another task queue (only done in testing).
Bug: webrtc:10365
Change-Id: I704249e00bf5e75e1f58fdda1809b955de20c304
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132713
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27596}
diff --git a/test/time_controller/simulated_time_controller.cc b/test/time_controller/simulated_time_controller.cc
index a592474..885732b 100644
--- a/test/time_controller/simulated_time_controller.cc
+++ b/test/time_controller/simulated_time_controller.cc
@@ -335,13 +335,16 @@
void SimulatedTimeControllerImpl::RunReadyRunners() {
RTC_DCHECK_RUN_ON(&thread_checker_);
+ rtc::CritScope lock(&lock_);
RTC_DCHECK_EQ(rtc::CurrentThreadId(), thread_id_);
Timestamp current_time = CurrentTime();
+ // Clearing |ready_runners_| in case this is a recursive call:
+ // RunReadyRunners -> Run -> Event::Wait -> Yield ->RunReadyRunners
+ ready_runners_.clear();
+
// We repeat until we have no ready left to handle tasks posted by ready
// runners.
while (true) {
- rtc::CritScope lock(&lock_);
- RTC_DCHECK(ready_runners_.empty());
for (auto* runner : runners_) {
if (yielded_.find(runner) == yielded_.end() &&
runner->GetNextRunTime() <= current_time) {