Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: webrtc/base/messagequeue.cc

Issue 2319303004: Fixing a couple cases that cause ProcessAllMessageQueues to hang. (Closed)
Patch Set: Use MQID_DISPOSE instead of NoOpMessageHandler. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/messagequeue_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/messagequeue.cc
diff --git a/webrtc/base/messagequeue.cc b/webrtc/base/messagequeue.cc
index ebf98f58a34e3539a85bb4068bddadf8eab9c678..503d5aff966bde3354352173891fe93e91350ce6 100644
--- a/webrtc/base/messagequeue.cc
+++ b/webrtc/base/messagequeue.cc
@@ -126,17 +126,34 @@ void MessageQueueManager::ProcessAllMessageQueues() {
}
void MessageQueueManager::ProcessAllMessageQueuesInternal() {
- // Post a delayed message at the current time and wait for it to be dispatched
- // on all queues, which will ensure that all messages that came before it were
- // also dispatched.
- volatile int queues_not_done;
- auto functor = [&queues_not_done] { AtomicOps::Decrement(&queues_not_done); };
- FunctorMessageHandler<void, decltype(functor)> handler(functor);
+ // This works by posting a delayed message at the current time and waiting
+ // for it to be dispatched on all queues, which will ensure that all messages
+ // that came before it were also dispatched.
+ volatile int queues_not_done = 0;
+
+ // This class is used so that whether the posted message is processed, or the
+ // message queue is simply cleared, queues_not_done gets decremented.
+ class ScopedIncrement : public MessageData {
+ public:
+ ScopedIncrement(volatile int* value) : value_(value) {
+ AtomicOps::Increment(value_);
+ }
+ ~ScopedIncrement() override { AtomicOps::Decrement(value_); }
+
+ private:
+ volatile int* value_;
+ };
+
{
DebugNonReentrantCritScope cs(&crit_, &locked_);
- queues_not_done = static_cast<int>(message_queues_.size());
for (MessageQueue* queue : message_queues_) {
- queue->PostDelayed(RTC_FROM_HERE, 0, &handler);
+ 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.
+ continue;
+ }
+ queue->PostDelayed(RTC_FROM_HERE, 0, nullptr, MQID_DISPOSE,
+ new ScopedIncrement(&queues_not_done));
}
}
// Note: One of the message queues may have been on this thread, which is why
« no previous file with comments | « no previous file | webrtc/base/messagequeue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698