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.

62 lines
1.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2016 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 "rtc_base/fake_clock.h"
  11. #include "rtc_base/checks.h"
  12. #include "rtc_base/message_queue.h"
  13. namespace rtc {
  14. int64_t FakeClock::TimeNanos() const {
  15. CritScope cs(&lock_);
  16. return time_ns_;
  17. }
  18. void FakeClock::SetTime(webrtc::Timestamp new_time) {
  19. CritScope cs(&lock_);
  20. RTC_DCHECK(new_time.us() * 1000 >= time_ns_);
  21. time_ns_ = new_time.us() * 1000;
  22. }
  23. void FakeClock::AdvanceTime(webrtc::TimeDelta delta) {
  24. CritScope cs(&lock_);
  25. time_ns_ += delta.ns();
  26. }
  27. void ThreadProcessingFakeClock::SetTime(webrtc::Timestamp time) {
  28. clock_.SetTime(time);
  29. // If message queues are waiting in a socket select() with a timeout provided
  30. // by the OS, they should wake up and dispatch all messages that are ready.
  31. MessageQueueManager::ProcessAllMessageQueuesForTesting();
  32. }
  33. void ThreadProcessingFakeClock::AdvanceTime(webrtc::TimeDelta delta) {
  34. clock_.AdvanceTime(delta);
  35. MessageQueueManager::ProcessAllMessageQueuesForTesting();
  36. }
  37. ScopedBaseFakeClock::ScopedBaseFakeClock() {
  38. prev_clock_ = SetClockForTesting(this);
  39. }
  40. ScopedBaseFakeClock::~ScopedBaseFakeClock() {
  41. SetClockForTesting(prev_clock_);
  42. }
  43. ScopedFakeClock::ScopedFakeClock() {
  44. prev_clock_ = SetClockForTesting(this);
  45. }
  46. ScopedFakeClock::~ScopedFakeClock() {
  47. SetClockForTesting(prev_clock_);
  48. }
  49. } // namespace rtc