Reland "Explicitly wrap main thread in test_main.cc."
This is a reland of 711a31aead9007e42dd73c302c8ec40f9e931619
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}
diff --git a/rtc_base/messagequeue.cc b/rtc_base/messagequeue.cc
index 035ff07..6ff73b5 100644
--- a/rtc_base/messagequeue.cc
+++ b/rtc_base/messagequeue.cc
@@ -124,7 +124,7 @@
}
}
-void MessageQueueManager::ProcessAllMessageQueues() {
+void MessageQueueManager::ProcessAllMessageQueuesForTesting() {
if (!instance_) {
return;
}
@@ -153,7 +153,7 @@
{
MarkProcessingCritScope cs(&crit_, &processing_);
for (MessageQueue* queue : message_queues_) {
- if (!queue->IsProcessingMessages()) {
+ if (!queue->IsProcessingMessagesForTesting()) {
// If the queue is not processing messages, it can
// be ignored. If we tried to post a message to it, it would be dropped
// or ignored.
@@ -163,11 +163,15 @@
new ScopedIncrement(&queues_not_done));
}
}
- // Note: One of the message queues may have been on this thread, which is why
- // we can't synchronously wait for queues_not_done to go to 0; we need to
- // process messages as well.
+
+ rtc::Thread* current = rtc::Thread::Current();
+ // Note: One of the message queues may have been on this thread, which is
+ // why we can't synchronously wait for queues_not_done to go to 0; we need
+ // to process messages as well.
while (AtomicOps::AcquireLoad(&queues_not_done) > 0) {
- rtc::Thread::Current()->ProcessMessages(0);
+ if (current) {
+ current->ProcessMessages(0);
+ }
}
}
@@ -245,7 +249,7 @@
return AtomicOps::AcquireLoad(&stop_) != 0;
}
-bool MessageQueue::IsProcessingMessages() {
+bool MessageQueue::IsProcessingMessagesForTesting() {
return !IsQuitting();
}