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}
This commit is contained in:
Sebastian Jansson 2019-04-12 15:39:38 +02:00 committed by Commit Bot
parent 6adbb49642
commit 1b40823870

View File

@ -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) {