SimulatedTimeController: remove lock recursions.

This change removes lock recursions and adds thread annotations.

Bug: webrtc:11567
Change-Id: If6c86adddf006367eefedf10cce819e776e6afc2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175111
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31294}
This commit is contained in:
Markus Handell 2020-05-15 18:43:05 +02:00 committed by Commit Bot
parent 37e42bed01
commit 222598d1bf
2 changed files with 17 additions and 13 deletions

View File

@ -57,7 +57,6 @@ SimulatedTimeControllerImpl::CreateTaskQueue(
std::unique_ptr<ProcessThread> SimulatedTimeControllerImpl::CreateProcessThread(
const char* thread_name) {
rtc::CritScope lock(&lock_);
auto process_thread =
std::make_unique<SimulatedProcessThread>(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(

View File

@ -52,32 +52,34 @@ class SimulatedTimeControllerImpl : public TaskQueueFactory,
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> 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<ProcessThread> CreateProcessThread(const char* thread_name);
std::unique_ptr<ProcessThread> CreateProcessThread(const char* thread_name)
RTC_LOCKS_EXCLUDED(time_lock_, lock_);
// Create thread using provided |socket_server|.
std::unique_ptr<rtc::Thread> CreateThread(
const std::string& name,
std::unique_ptr<rtc::SocketServer> socket_server);
std::unique_ptr<rtc::SocketServer> 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);