Chromium Code Reviews| Index: webrtc/base/messagequeue.cc |
| diff --git a/webrtc/base/messagequeue.cc b/webrtc/base/messagequeue.cc |
| index 8dd84cb89c256d4b3fd99ab6ba1240ef3300954e..1c8b81f804eb7506d57cbd49ba54dc83374e3e47 100644 |
| --- a/webrtc/base/messagequeue.cc |
| +++ b/webrtc/base/messagequeue.cc |
| @@ -146,9 +146,7 @@ void MessageQueueManager::ProcessAllMessageQueuesInternal() { |
| { |
| DebugNonReentrantCritScope cs(&crit_, &locked_); |
| for (MessageQueue* queue : message_queues_) { |
| - if (queue->IsQuitting()) { |
| - // If the queue is quitting, it's done processing messages so it can |
| - // be ignored. If we tried to post a message to it, it would be dropped. |
| + if (!queue->WaitForProcess()) { |
| continue; |
| } |
| queue->PostDelayed(RTC_FROM_HERE, 0, nullptr, MQID_DISPOSE, |
| @@ -159,7 +157,10 @@ void MessageQueueManager::ProcessAllMessageQueuesInternal() { |
| // 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); |
| + // We have to limit the number of messages that may be processed |
| + // because we may get into an infinite processing loop even after |
| + // "queues_not_done" is 0. |
|
Taylor Brandstetter
2017/02/06 19:23:42
How does that happen? That seems like a deeper pro
|
| + rtc::Thread::Current()->ProcessMessages(0, 100); |
| } |
| } |
| @@ -250,6 +251,11 @@ void MessageQueue::Quit() { |
| bool MessageQueue::IsQuitting() { |
| return AtomicOps::AcquireLoad(&stop_) != 0; |
| } |
| +bool MessageQueue::WaitForProcess() { |
| + // If the queue is quitting, it's done processing messages so it can |
| + // be ignored. If we tried to post a message to it, it would be dropped. |
| + return !IsQuitting(); |
| +} |
| void MessageQueue::Restart() { |
| AtomicOps::ReleaseStore(&stop_, 0); |