diff --git a/test/time_controller/simulated_time_controller.cc b/test/time_controller/simulated_time_controller.cc index a81083b4fb..769be3ff78 100644 --- a/test/time_controller/simulated_time_controller.cc +++ b/test/time_controller/simulated_time_controller.cc @@ -57,7 +57,6 @@ SimulatedTimeControllerImpl::CreateTaskQueue( std::unique_ptr SimulatedTimeControllerImpl::CreateProcessThread( const char* thread_name) { - rtc::CritScope lock(&lock_); auto process_thread = std::make_unique(this, thread_name); Register(process_thread.get()); @@ -117,10 +116,12 @@ void SimulatedTimeControllerImpl::RunReadyRunners() { while (!ready_runners_.empty()) { auto* runner = ready_runners_.front(); ready_runners_.pop_front(); + lock_.Leave(); // Note that the RunReady function might indirectly cause a call to - // Unregister() which will recursively grab |lock_| again to remove items - // from |ready_runners_|. + // Unregister() which will grab |lock_| again to remove items from + // |ready_runners_|. runner->RunReady(current_time); + lock_.Enter(); } } } @@ -169,6 +170,7 @@ void SimulatedTimeControllerImpl::StartYield(TaskQueueBase* yielding_from) { void SimulatedTimeControllerImpl::StopYield(TaskQueueBase* yielding_from) { yielded_.erase(yielding_from); } + } // namespace sim_time_impl GlobalSimulatedTimeController::GlobalSimulatedTimeController( diff --git a/test/time_controller/simulated_time_controller.h b/test/time_controller/simulated_time_controller.h index 758f90989e..48112b3a31 100644 --- a/test/time_controller/simulated_time_controller.h +++ b/test/time_controller/simulated_time_controller.h @@ -52,32 +52,34 @@ class SimulatedTimeControllerImpl : public TaskQueueFactory, std::unique_ptr CreateTaskQueue( absl::string_view name, - Priority priority) const override; + Priority priority) const RTC_LOCKS_EXCLUDED(time_lock_) override; // Implements the YieldInterface by running ready tasks on all task queues, // except that if this method is called from a task, the task queue running // that task is skipped. - void YieldExecution() override; + void YieldExecution() RTC_LOCKS_EXCLUDED(time_lock_, lock_) override; // Create process thread with the name |thread_name|. - std::unique_ptr CreateProcessThread(const char* thread_name); + std::unique_ptr CreateProcessThread(const char* thread_name) + RTC_LOCKS_EXCLUDED(time_lock_, lock_); // Create thread using provided |socket_server|. std::unique_ptr CreateThread( const std::string& name, - std::unique_ptr socket_server); + std::unique_ptr socket_server) + RTC_LOCKS_EXCLUDED(time_lock_, lock_); // Runs all runners in |runners_| that has tasks or modules ready for // execution. - void RunReadyRunners(); + void RunReadyRunners() RTC_LOCKS_EXCLUDED(time_lock_, lock_); // Return |current_time_|. - Timestamp CurrentTime() const; + Timestamp CurrentTime() const RTC_LOCKS_EXCLUDED(time_lock_); // Return min of runner->GetNextRunTime() for runner in |runners_|. - Timestamp NextRunTime() const; + Timestamp NextRunTime() const RTC_LOCKS_EXCLUDED(lock_); // Set |current_time_| to |target_time|. - void AdvanceTime(Timestamp target_time); + void AdvanceTime(Timestamp target_time) RTC_LOCKS_EXCLUDED(time_lock_); // Adds |runner| to |runners_|. - void Register(SimulatedSequenceRunner* runner); + void Register(SimulatedSequenceRunner* runner) RTC_LOCKS_EXCLUDED(lock_); // Removes |runner| from |runners_|. - void Unregister(SimulatedSequenceRunner* runner); + void Unregister(SimulatedSequenceRunner* runner) RTC_LOCKS_EXCLUDED(lock_); // Indicates that |yielding_from| is not ready to run. void StartYield(TaskQueueBase* yielding_from);