webrtc/rtc_base/fakeclock.cc
Niels Möller 8909a63aca Reland "Explicitly wrap main thread in test_main.cc."
This is a reland of 711a31aead

Changes since original landing:

Rename methods only used by tests, mainly via FakeClock,

  MessageQueueManager::ProcessAllMessageQueues
     --> ProcessAllMessageQueuesForTesting

  MessageQueue::IsProcessingMessages
     --> IsProcessingMessagesForTesting

Fix the handling of null rtc::Thread::Current() in
ProcessAllMessageQueuesInternal().

Add override Thread::IsProcessingMessagesForTesting() to return false
for the wrapped main thread, unless it's also the current thread. In
tests, the main thread is typically not processing any messages,
but blocked in an Event::Wait().

Original change's description:
> Explicitly wrap main thread in test_main.cc.
>
> Bug: webrtc:9714
> Change-Id: I6ee234f9a0b88b3656a683f2455c3e4b2acf0d54
> Reviewed-on: https://webrtc-review.googlesource.com/97683
> Reviewed-by: Tommi <tommi@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#24560}

Bug: webrtc:9714
Change-Id: I6f022d46aaf1e28f86f09f2d68c1803b69770126
Reviewed-on: https://webrtc-review.googlesource.com/98060
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24596}
2018-09-06 08:38:18 +00:00

50 lines
1.3 KiB
C++

/*
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtc_base/fakeclock.h"
#include "rtc_base/checks.h"
#include "rtc_base/messagequeue.h"
namespace rtc {
int64_t FakeClock::TimeNanos() const {
CritScope cs(&lock_);
return time_;
}
void FakeClock::SetTimeNanos(int64_t nanos) {
{
CritScope cs(&lock_);
RTC_DCHECK(nanos >= time_);
time_ = nanos;
}
// If message queues are waiting in a socket select() with a timeout provided
// by the OS, they should wake up and dispatch all messages that are ready.
MessageQueueManager::ProcessAllMessageQueuesForTesting();
}
void FakeClock::AdvanceTime(webrtc::TimeDelta delta) {
{
CritScope cs(&lock_);
time_ += delta.ns();
}
MessageQueueManager::ProcessAllMessageQueuesForTesting();
}
ScopedFakeClock::ScopedFakeClock() {
prev_clock_ = SetClockForTesting(this);
}
ScopedFakeClock::~ScopedFakeClock() {
SetClockForTesting(prev_clock_);
}
} // namespace rtc