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

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: Reverted PS #7, updated comments Created 4 years, 10 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 | « webrtc/base/messagequeue.h ('k') | webrtc/base/thread.h » ('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 857cf12927cd89eb6cea31210065edf3574e5b24..bbdb941ffab4941107b347023f5ab23e0b762b42 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 init_queue)
: ss_(ss), fStop_(false), fPeekKeep_(false),
- dmsgq_next_num_(0) {
+ dmsgq_next_num_(0), fInitialized_(false), 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,30 @@ MessageQueue::MessageQueue(SocketServer* ss)
ss_ = default_ss_.get();
}
ss_->SetMessageQueue(this);
- MessageQueueManager::Add(this);
+ if (init_queue) {
+ DoInit();
+ }
}
MessageQueue::~MessageQueue() {
+ DoDestroy();
+}
+
+void MessageQueue::DoInit() {
+ if (fInitialized_) {
+ return;
+ }
+
+ fInitialized_ = true;
+ MessageQueueManager::Add(this);
+}
+
+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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698