From 1b40823870eaa17a9883a3623c5ec4912faada0b Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Fri, 12 Apr 2019 15:39:38 +0200 Subject: [PATCH] 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 Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#27596} --- test/time_controller/simulated_time_controller.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/time_controller/simulated_time_controller.cc b/test/time_controller/simulated_time_controller.cc index a592474a2b..885732b1ec 100644 --- a/test/time_controller/simulated_time_controller.cc +++ b/test/time_controller/simulated_time_controller.cc @@ -335,13 +335,16 @@ void SimulatedTimeControllerImpl::YieldExecution() { 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) {