diff --git a/api/test/time_controller.h b/api/test/time_controller.h index 616622b942..70aabdaeef 100644 --- a/api/test/time_controller.h +++ b/api/test/time_controller.h @@ -40,12 +40,6 @@ class TimeController { // Allow task queues and process threads created by this instance to execute // for the given |duration|. virtual void AdvanceTime(TimeDelta duration) = 0; - // Execute closure in an implementation defined scope where rtc::Event::Wait - // might yield to execute other tasks. This allows doing blocking waits on - // tasks on other task queues froma a task queue without deadlocking. - virtual void InvokeWithControlledYield(std::function closure) = 0; - // Returns a YieldInterface which can be installed as a ScopedYieldPolicy. - virtual rtc::YieldInterface* YieldInterface() = 0; }; // Interface for telling time, scheduling an event to fire at a particular time, diff --git a/test/scenario/call_client.cc b/test/scenario/call_client.cc index f89b13f0d8..5823656543 100644 --- a/test/scenario/call_client.cc +++ b/test/scenario/call_client.cc @@ -321,8 +321,7 @@ void CallClient::AddExtensions(std::vector extensions) { } void CallClient::SendTask(std::function task) { - time_controller_->InvokeWithControlledYield( - [&] { task_queue_.SendTask(std::move(task), RTC_FROM_HERE); }); + task_queue_.SendTask(std::move(task), RTC_FROM_HERE); } CallClientPair::~CallClientPair() = default; diff --git a/test/time_controller/external_time_controller.cc b/test/time_controller/external_time_controller.cc index 51e5641f43..bb60d89980 100644 --- a/test/time_controller/external_time_controller.cc +++ b/test/time_controller/external_time_controller.cc @@ -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 closure) { - rtc::ScopedYieldPolicy policy(YieldInterface()); - closure(); -} - -rtc::YieldInterface* ExternalTimeController::YieldInterface() { - return &impl_; -} - std::unique_ptr ExternalTimeController::CreateTaskQueue( absl::string_view name, diff --git a/test/time_controller/external_time_controller.h b/test/time_controller/external_time_controller.h index 3ae302eff7..869a78fb05 100644 --- a/test/time_controller/external_time_controller.h +++ b/test/time_controller/external_time_controller.h @@ -38,8 +38,6 @@ class ExternalTimeController : public TimeController, public TaskQueueFactory { std::unique_ptr CreateProcessThread( const char* thread_name) override; void AdvanceTime(TimeDelta duration) override; - void InvokeWithControlledYield(std::function closure) override; - rtc::YieldInterface* YieldInterface() override; // Implementation of TaskQueueFactory. std::unique_ptr CreateTaskQueue( @@ -59,6 +57,7 @@ class ExternalTimeController : public TimeController, public TaskQueueFactory { ControlledAlarmClock* alarm_; sim_time_impl::SimulatedTimeControllerImpl impl_; + rtc::ScopedYieldPolicy yield_policy_; // Overrides the global rtc::Clock to ensure that it reports the same times as // the time controller. diff --git a/test/time_controller/external_time_controller_unittest.cc b/test/time_controller/external_time_controller_unittest.cc index b0b09cb78a..d93b42aaac 100644 --- a/test/time_controller/external_time_controller_unittest.cc +++ b/test/time_controller/external_time_controller_unittest.cc @@ -138,11 +138,9 @@ TEST(ExternalTimeControllerTest, YieldForTask) { time_simulation.GetTaskQueueFactory()->CreateTaskQueue( "TestQueue", TaskQueueFactory::Priority::NORMAL)); - time_simulation.InvokeWithControlledYield([&] { - rtc::Event event; - task_queue.PostTask([&] { event.Set(); }); - EXPECT_TRUE(event.Wait(200)); - }); + rtc::Event event; + task_queue.PostTask([&] { event.Set(); }); + EXPECT_TRUE(event.Wait(200)); } TEST(ExternalTimeControllerTest, TasksYieldToEachOther) { diff --git a/test/time_controller/real_time_controller.cc b/test/time_controller/real_time_controller.cc index 0494bc0f1f..732f1bdd38 100644 --- a/test/time_controller/real_time_controller.cc +++ b/test/time_controller/real_time_controller.cc @@ -34,15 +34,6 @@ void RealTimeController::AdvanceTime(TimeDelta duration) { SleepMs(duration.ms()); } -void RealTimeController::InvokeWithControlledYield( - std::function closure) { - closure(); -} - -rtc::YieldInterface* RealTimeController::YieldInterface() { - return nullptr; -} - RealTimeController* GlobalRealTimeController() { static RealTimeController* time_controller = new RealTimeController(); return time_controller; diff --git a/test/time_controller/real_time_controller.h b/test/time_controller/real_time_controller.h index 58d7682d6f..873ef90178 100644 --- a/test/time_controller/real_time_controller.h +++ b/test/time_controller/real_time_controller.h @@ -29,8 +29,6 @@ class RealTimeController : public TimeController { std::unique_ptr CreateProcessThread( const char* thread_name) override; void AdvanceTime(TimeDelta duration) override; - void InvokeWithControlledYield(std::function closure) override; - rtc::YieldInterface* YieldInterface() override; private: std::unique_ptr task_queue_factory_; diff --git a/test/time_controller/simulated_time_controller.cc b/test/time_controller/simulated_time_controller.cc index c2c135abc9..4c8a1e1938 100644 --- a/test/time_controller/simulated_time_controller.cc +++ b/test/time_controller/simulated_time_controller.cc @@ -399,7 +399,7 @@ void SimulatedTimeControllerImpl::Unregister(SimulatedSequenceRunner* runner) { GlobalSimulatedTimeController::GlobalSimulatedTimeController( Timestamp start_time) - : sim_clock_(start_time.us()), impl_(start_time) { + : sim_clock_(start_time.us()), impl_(start_time), yield_policy_(&impl_) { global_clock_.SetTime(start_time); } @@ -434,16 +434,4 @@ void GlobalSimulatedTimeController::AdvanceTime(TimeDelta duration) { } } -void GlobalSimulatedTimeController::InvokeWithControlledYield( - std::function closure) { - rtc::ScopedYieldPolicy yield_policy(&impl_); - closure(); -} - -rtc::YieldInterface* GlobalSimulatedTimeController::YieldInterface() { - return &impl_; -} - -// namespace sim_time_impl - } // namespace webrtc diff --git a/test/time_controller/simulated_time_controller.h b/test/time_controller/simulated_time_controller.h index 919b858981..8725b06dc1 100644 --- a/test/time_controller/simulated_time_controller.h +++ b/test/time_controller/simulated_time_controller.h @@ -91,14 +91,13 @@ class GlobalSimulatedTimeController : public TimeController { std::unique_ptr CreateProcessThread( const char* thread_name) override; void AdvanceTime(TimeDelta duration) override; - void InvokeWithControlledYield(std::function closure) override; - rtc::YieldInterface* YieldInterface() override; private: rtc::ScopedBaseFakeClock global_clock_; // Provides simulated CurrentNtpInMilliseconds() SimulatedClock sim_clock_; sim_time_impl::SimulatedTimeControllerImpl impl_; + rtc::ScopedYieldPolicy yield_policy_; }; } // namespace webrtc diff --git a/video/video_receive_stream_unittest.cc b/video/video_receive_stream_unittest.cc index b6c4200bd8..503660eca6 100644 --- a/video/video_receive_stream_unittest.cc +++ b/video/video_receive_stream_unittest.cc @@ -493,26 +493,18 @@ class VideoReceiveStreamTestWithSimulatedClock : public ::testing::Test { &call_stats_, time_controller_.GetClock(), new VCMTiming(time_controller_.GetClock())) { - time_controller_.InvokeWithControlledYield( - [this] { video_receive_stream_.Start(); }); - } - - ~VideoReceiveStreamTestWithSimulatedClock() { - time_controller_.InvokeWithControlledYield( - [this] { video_receive_stream_.Stop(); }); + video_receive_stream_.Start(); } void OnFrameDecoded() { event_->Set(); } void PassEncodedFrameAndWait( std::unique_ptr frame) { - time_controller_.InvokeWithControlledYield([this, &frame] { event_ = std::make_unique(); // This call will eventually end up in the Decoded method where the // event is set. video_receive_stream_.OnCompleteFrame(std::move(frame)); event_->Wait(rtc::Event::kForever); - }); } protected: