You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #ifndef TEST_TIME_CONTROLLER_TIME_CONTROLLER_H_
  11. #define TEST_TIME_CONTROLLER_TIME_CONTROLLER_H_
  12. #include <functional>
  13. #include <memory>
  14. #include "api/task_queue/task_queue_factory.h"
  15. #include "api/units/time_delta.h"
  16. #include "modules/utility/include/process_thread.h"
  17. #include "system_wrappers/include/clock.h"
  18. namespace webrtc {
  19. // Interface for controlling time progress. This allows us to execute test code
  20. // in either real time or simulated time by using different implementation of
  21. // this interface.
  22. class TimeController {
  23. public:
  24. virtual ~TimeController() = default;
  25. // Provides a clock instance that follows implementation defined time
  26. // progress.
  27. virtual Clock* GetClock() = 0;
  28. // The returned factory will created task queues that runs in implementation
  29. // defined time domain.
  30. virtual TaskQueueFactory* GetTaskQueueFactory() = 0;
  31. // Creates a process thread.
  32. virtual std::unique_ptr<ProcessThread> CreateProcessThread(
  33. const char* thread_name) = 0;
  34. // Allow task queues and process threads created by this instance to execute
  35. // for the given |duration|.
  36. virtual void Sleep(TimeDelta duration) = 0;
  37. // Execute closure in an implementation defined scope where rtc::Event::Wait
  38. // might yield to execute other tasks. This allows doing blocking waits on
  39. // tasks on other task queues froma a task queue without deadlocking.
  40. virtual void InvokeWithControlledYield(std::function<void()> closure) = 0;
  41. };
  42. } // namespace webrtc
  43. #endif // TEST_TIME_CONTROLLER_TIME_CONTROLLER_H_