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

Unified Diff: webrtc/base/messagequeue.cc

Issue 1666863002: Fix race between Thread ctor/dtor and MessageQueueManager registrations. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added unittest. Created 4 years, 11 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
Index: webrtc/base/messagequeue.cc
diff --git a/webrtc/base/messagequeue.cc b/webrtc/base/messagequeue.cc
index 857cf12927cd89eb6cea31210065edf3574e5b24..0efecff6850cd705c25b343681087dfb988f6212 100644
--- a/webrtc/base/messagequeue.cc
+++ b/webrtc/base/messagequeue.cc
@@ -116,9 +116,9 @@ void MessageQueueManager::ClearInternal(MessageHandler *handler) {
//------------------------------------------------------------------
// MessageQueue
-MessageQueue::MessageQueue(SocketServer* ss)
+MessageQueue::MessageQueue(SocketServer* ss, bool add_to_queue_manager)
: ss_(ss), fStop_(false), fPeekKeep_(false),
- dmsgq_next_num_(0) {
+ dmsgq_next_num_(0), fDestroyed_(false) {
if (!ss_) {
// Currently, MessageQueue holds a socket server, and is the base class for
// Thread. It seems like it makes more sense for Thread to hold the socket
@@ -129,10 +129,21 @@ MessageQueue::MessageQueue(SocketServer* ss)
ss_ = default_ss_.get();
}
ss_->SetMessageQueue(this);
- MessageQueueManager::Add(this);
+ if (add_to_queue_manager) {
+ MessageQueueManager::Add(this);
+ }
}
MessageQueue::~MessageQueue() {
+ DoDestroy();
+}
+
+void MessageQueue::DoDestroy() {
+ if (fDestroyed_) {
+ return;
+ }
+
+ fDestroyed_ = true;
// The signal is done from here to ensure
// that it always gets called when the queue
// is going away.
« no previous file with comments | « webrtc/base/messagequeue.h ('k') | webrtc/base/thread.h » ('j') | webrtc/base/thread_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698