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

Unified Diff: webrtc/base/messagequeue.cc

Issue 1714463003: Revert of Prevent data race in MessageQueue. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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.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 61aa61192bbad69d87ddf5e79aab3a5af3ce290f..bbdb941ffab4941107b347023f5ab23e0b762b42 100644
--- a/webrtc/base/messagequeue.cc
+++ b/webrtc/base/messagequeue.cc
@@ -117,8 +117,8 @@
// MessageQueue
MessageQueue::MessageQueue(SocketServer* ss, bool init_queue)
- : fStop_(false), fPeekKeep_(false),
- dmsgq_next_num_(0), fInitialized_(false), fDestroyed_(false), ss_(ss) {
+ : ss_(ss), fStop_(false), fPeekKeep_(false),
+ 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
@@ -159,37 +159,19 @@
SignalQueueDestroyed();
MessageQueueManager::Remove(this);
Clear(NULL);
-
- SharedScope ss(&ss_lock_);
if (ss_) {
ss_->SetMessageQueue(NULL);
}
}
-SocketServer* MessageQueue::socketserver() {
- SharedScope ss(&ss_lock_);
- return ss_;
-}
-
void MessageQueue::set_socketserver(SocketServer* ss) {
- // Need to lock exclusively here to prevent simultaneous modifications from
- // other threads. Can't be a shared lock to prevent races with other reading
- // threads.
- // Other places that only read "ss_" can use a shared lock as simultaneous
- // read access is allowed.
- ExclusiveScope es(&ss_lock_);
ss_ = ss ? ss : default_ss_.get();
ss_->SetMessageQueue(this);
}
-void MessageQueue::WakeUpSocketServer() {
- SharedScope ss(&ss_lock_);
- ss_->WakeUp();
-}
-
void MessageQueue::Quit() {
fStop_ = true;
- WakeUpSocketServer();
+ ss_->WakeUp();
}
bool MessageQueue::IsQuitting() {
@@ -295,12 +277,9 @@
cmsNext = cmsDelayNext;
}
- {
- // Wait and multiplex in the meantime
- SharedScope ss(&ss_lock_);
- if (!ss_->Wait(cmsNext, process_io))
- return false;
- }
+ // Wait and multiplex in the meantime
+ if (!ss_->Wait(cmsNext, process_io))
+ return false;
// If the specified timeout expired, return
@@ -328,18 +307,16 @@
// Add the message to the end of the queue
// Signal for the multiplexer to return
- {
- CritScope cs(&crit_);
- Message msg;
- msg.phandler = phandler;
- msg.message_id = id;
- msg.pdata = pdata;
- if (time_sensitive) {
- msg.ts_sensitive = Time() + kMaxMsgLatency;
- }
- msgq_.push_back(msg);
- }
- WakeUpSocketServer();
+ CritScope cs(&crit_);
+ Message msg;
+ msg.phandler = phandler;
+ msg.message_id = id;
+ msg.pdata = pdata;
+ if (time_sensitive) {
+ msg.ts_sensitive = Time() + kMaxMsgLatency;
+ }
+ msgq_.push_back(msg);
+ ss_->WakeUp();
}
void MessageQueue::PostDelayed(int cmsDelay,
@@ -368,20 +345,18 @@
// Add to the priority queue. Gets sorted soonest first.
// Signal for the multiplexer to return.
- {
- CritScope cs(&crit_);
- Message msg;
- msg.phandler = phandler;
- msg.message_id = id;
- msg.pdata = pdata;
- DelayedMessage dmsg(cmsDelay, tstamp, dmsgq_next_num_, msg);
- dmsgq_.push(dmsg);
- // If this message queue processes 1 message every millisecond for 50 days,
- // we will wrap this number. Even then, only messages with identical times
- // will be misordered, and then only briefly. This is probably ok.
- VERIFY(0 != ++dmsgq_next_num_);
- }
- WakeUpSocketServer();
+ CritScope cs(&crit_);
+ Message msg;
+ msg.phandler = phandler;
+ msg.message_id = id;
+ msg.pdata = pdata;
+ DelayedMessage dmsg(cmsDelay, tstamp, dmsgq_next_num_, msg);
+ dmsgq_.push(dmsg);
+ // If this message queue processes 1 message every millisecond for 50 days,
+ // we will wrap this number. Even then, only messages with identical times
+ // will be misordered, and then only briefly. This is probably ok.
+ VERIFY(0 != ++dmsgq_next_num_);
+ ss_->WakeUp();
}
int MessageQueue::GetDelay() {
« no previous file with comments | « webrtc/base/messagequeue.h ('k') | webrtc/base/thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698