Moves ownership of time controller into NetworkEmulationManager.
This makes it easier to maintain consistency between real time and simulated time modes. The RealTimeController is updated to use an explicit main thread, this ensures that pending destruction tasks are run as the network emulator goes out of scope. Bug: webrtc:11255 Change-Id: Ie73ab778c78a68d7c58c0f857f14a8d8ac027c67 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166164 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Reviewed-by: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30342}
This commit is contained in:
committed by
Commit Bot
parent
402379f1f3
commit
6ce033a863
@ -14,8 +14,28 @@
|
||||
#include "system_wrappers/include/sleep.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
class MainThread : public rtc::Thread {
|
||||
public:
|
||||
MainThread()
|
||||
: Thread(std::make_unique<rtc::NullSocketServer>(), false),
|
||||
current_setter_(this) {
|
||||
DoInit();
|
||||
}
|
||||
~MainThread() {
|
||||
Stop();
|
||||
DoDestroy();
|
||||
}
|
||||
|
||||
private:
|
||||
CurrentThreadSetter current_setter_;
|
||||
};
|
||||
} // namespace
|
||||
RealTimeController::RealTimeController()
|
||||
: task_queue_factory_(CreateDefaultTaskQueueFactory()) {}
|
||||
: task_queue_factory_(CreateDefaultTaskQueueFactory()),
|
||||
main_thread_(std::make_unique<MainThread>()) {
|
||||
main_thread_->SetName("Main", this);
|
||||
}
|
||||
|
||||
Clock* RealTimeController::GetClock() {
|
||||
return Clock::GetRealTimeClock();
|
||||
@ -42,16 +62,11 @@ std::unique_ptr<rtc::Thread> RealTimeController::CreateThread(
|
||||
}
|
||||
|
||||
rtc::Thread* RealTimeController::GetMainThread() {
|
||||
return rtc::Thread::Current();
|
||||
return main_thread_.get();
|
||||
}
|
||||
|
||||
void RealTimeController::AdvanceTime(TimeDelta duration) {
|
||||
GetMainThread()->ProcessMessages(duration.ms());
|
||||
}
|
||||
|
||||
RealTimeController* GlobalRealTimeController() {
|
||||
static RealTimeController* time_controller = new RealTimeController();
|
||||
return time_controller;
|
||||
main_thread_->ProcessMessages(duration.ms());
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -36,10 +36,9 @@ class RealTimeController : public TimeController {
|
||||
|
||||
private:
|
||||
const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
|
||||
const std::unique_ptr<rtc::Thread> main_thread_;
|
||||
};
|
||||
|
||||
RealTimeController* GlobalRealTimeController();
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // TEST_TIME_CONTROLLER_REAL_TIME_CONTROLLER_H_
|
||||
|
||||
@ -19,20 +19,7 @@ namespace webrtc {
|
||||
class SimulatedThread : public rtc::Thread,
|
||||
public sim_time_impl::SimulatedSequenceRunner {
|
||||
public:
|
||||
class CurrentThreadSetter : CurrentTaskQueueSetter {
|
||||
public:
|
||||
explicit CurrentThreadSetter(Thread* thread)
|
||||
: CurrentTaskQueueSetter(thread),
|
||||
manager_(rtc::ThreadManager::Instance()),
|
||||
previous_(manager_->CurrentThread()) {
|
||||
manager_->ChangeCurrentThreadForTest(thread);
|
||||
}
|
||||
~CurrentThreadSetter() { manager_->ChangeCurrentThreadForTest(previous_); }
|
||||
|
||||
private:
|
||||
rtc::ThreadManager* const manager_;
|
||||
rtc::Thread* const previous_;
|
||||
};
|
||||
using CurrentThreadSetter = CurrentThreadSetter;
|
||||
SimulatedThread(sim_time_impl::SimulatedTimeControllerImpl* handler,
|
||||
absl::string_view name,
|
||||
std::unique_ptr<rtc::SocketServer> socket_server);
|
||||
|
||||
Reference in New Issue
Block a user