Sebastian Jansson | 0d617cc | 2019-03-22 15:22:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | #include "test/time_controller/real_time_controller.h" |
| 11 | |
Danil Chapovalov | 28de7cf | 2019-04-12 19:25:06 +0200 | [diff] [blame] | 12 | #include "api/task_queue/default_task_queue_factory.h" |
Sebastian Jansson | 0d617cc | 2019-03-22 15:22:16 +0100 | [diff] [blame] | 13 | #include "system_wrappers/include/sleep.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | |
Danil Chapovalov | 28de7cf | 2019-04-12 19:25:06 +0200 | [diff] [blame] | 17 | RealTimeController::RealTimeController() |
| 18 | : task_queue_factory_(CreateDefaultTaskQueueFactory()) {} |
| 19 | |
Sebastian Jansson | 0d617cc | 2019-03-22 15:22:16 +0100 | [diff] [blame] | 20 | Clock* RealTimeController::GetClock() { |
| 21 | return Clock::GetRealTimeClock(); |
| 22 | } |
| 23 | |
| 24 | TaskQueueFactory* RealTimeController::GetTaskQueueFactory() { |
Danil Chapovalov | 28de7cf | 2019-04-12 19:25:06 +0200 | [diff] [blame] | 25 | return task_queue_factory_.get(); |
Sebastian Jansson | 0d617cc | 2019-03-22 15:22:16 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | std::unique_ptr<ProcessThread> RealTimeController::CreateProcessThread( |
| 29 | const char* thread_name) { |
| 30 | return ProcessThread::Create(thread_name); |
| 31 | } |
| 32 | |
| 33 | void RealTimeController::Sleep(TimeDelta duration) { |
| 34 | SleepMs(duration.ms()); |
| 35 | } |
| 36 | |
| 37 | void RealTimeController::InvokeWithControlledYield( |
| 38 | std::function<void()> closure) { |
| 39 | closure(); |
| 40 | } |
| 41 | |
Sebastian Jansson | 5d97f55 | 2019-04-15 14:43:03 +0200 | [diff] [blame] | 42 | RealTimeController* GlobalRealTimeController() { |
| 43 | static RealTimeController* time_controller = new RealTimeController(); |
| 44 | return time_controller; |
| 45 | } |
| 46 | |
Sebastian Jansson | 0d617cc | 2019-03-22 15:22:16 +0100 | [diff] [blame] | 47 | } // namespace webrtc |