From dd45eb68018a621a81ffa6983519573496efe185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Tue, 19 Jan 2016 15:22:32 +0100 Subject: [PATCH] Remove use-after-free when quality tests stall. Reduces TSan warnings when running screenshare FullStack tests. BUG= R=sprang@webrtc.org Review URL: https://codereview.webrtc.org/1601033004 . Cr-Commit-Position: refs/heads/master@{#11305} --- webrtc/video/video_quality_test.cc | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc index 08ae0a9cee..6e8c9902c6 100644 --- a/webrtc/video/video_quality_test.cc +++ b/webrtc/video/video_quality_test.cc @@ -73,7 +73,7 @@ class VideoAnalyzer : public PacketReceiver, avg_ssim_threshold_(avg_ssim_threshold), stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), comparison_available_event_(false, false), - done_(false, false) { + done_(true, false) { // Create thread pool for CPU-expensive PSNR/SSIM calculations. // Try to use about as many threads as cores, but leave kMinCoresLeft alone, @@ -243,18 +243,18 @@ class VideoAnalyzer : public PacketReceiver, last_frames_processed = frames_processed; continue; } - ASSERT_GT(frames_processed, last_frames_processed) - << "Analyzer stalled while waiting for test to finish."; + if (frames_processed == last_frames_processed) { + EXPECT_GT(frames_processed, last_frames_processed) + << "Analyzer stalled while waiting for test to finish."; + done_.Set(); + break; + } last_frames_processed = frames_processed; } if (iteration > 0) printf("- Farewell, sweet Concorde!\n"); - // Signal stats polling thread if that is still waiting and stop it now, - // since it uses the send_stream_ reference that might be reclaimed after - // returning from this method. - done_.Set(); stats_polling_thread_.Stop(); } @@ -359,12 +359,8 @@ class VideoAnalyzer : public PacketReceiver, } bool PollStats() { - if (done_.Wait(kSendStatsPollingIntervalMs)) { - // Set event again to make sure main thread is also signaled, then we're - // done. - done_.Set(); + if (done_.Wait(kSendStatsPollingIntervalMs)) return false; - } VideoSendStream::Stats stats = send_stream_->GetStats();