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

Side by Side Diff: webrtc/base/messagequeue.h

Issue 1675923002: Prevent data race in MessageQueue. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed initialization order. 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/base/messagequeue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_MESSAGEQUEUE_H_ 11 #ifndef WEBRTC_BASE_MESSAGEQUEUE_H_
12 #define WEBRTC_BASE_MESSAGEQUEUE_H_ 12 #define WEBRTC_BASE_MESSAGEQUEUE_H_
13 13
14 #include <string.h> 14 #include <string.h>
15 15
16 #include <algorithm> 16 #include <algorithm>
17 #include <list> 17 #include <list>
18 #include <queue> 18 #include <queue>
19 #include <vector> 19 #include <vector>
20 20
21 #include "webrtc/base/basictypes.h" 21 #include "webrtc/base/basictypes.h"
22 #include "webrtc/base/constructormagic.h" 22 #include "webrtc/base/constructormagic.h"
23 #include "webrtc/base/criticalsection.h" 23 #include "webrtc/base/criticalsection.h"
24 #include "webrtc/base/messagehandler.h" 24 #include "webrtc/base/messagehandler.h"
25 #include "webrtc/base/scoped_ptr.h" 25 #include "webrtc/base/scoped_ptr.h"
26 #include "webrtc/base/scoped_ref_ptr.h" 26 #include "webrtc/base/scoped_ref_ptr.h"
27 #include "webrtc/base/sharedexclusivelock.h"
27 #include "webrtc/base/sigslot.h" 28 #include "webrtc/base/sigslot.h"
28 #include "webrtc/base/socketserver.h" 29 #include "webrtc/base/socketserver.h"
29 #include "webrtc/base/timeutils.h" 30 #include "webrtc/base/timeutils.h"
31 #include "webrtc/base/thread_annotations.h"
30 32
31 namespace rtc { 33 namespace rtc {
32 34
33 struct Message; 35 struct Message;
34 class MessageQueue; 36 class MessageQueue;
35 37
36 // MessageQueueManager does cleanup of of message queues 38 // MessageQueueManager does cleanup of of message queues
37 39
38 class MessageQueueManager { 40 class MessageQueueManager {
39 public: 41 public:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // being created. 176 // being created.
175 explicit MessageQueue(SocketServer* ss = NULL, 177 explicit MessageQueue(SocketServer* ss = NULL,
176 bool init_queue = true); 178 bool init_queue = true);
177 179
178 // NOTE: SUBCLASSES OF MessageQueue THAT OVERRIDE Clear MUST CALL 180 // NOTE: SUBCLASSES OF MessageQueue THAT OVERRIDE Clear MUST CALL
179 // DoDestroy() IN THEIR DESTRUCTORS! This is required to avoid a data race 181 // DoDestroy() IN THEIR DESTRUCTORS! This is required to avoid a data race
180 // between the destructor modifying the vtable, and the MessageQueueManager 182 // between the destructor modifying the vtable, and the MessageQueueManager
181 // calling Clear on the object from a different thread. 183 // calling Clear on the object from a different thread.
182 virtual ~MessageQueue(); 184 virtual ~MessageQueue();
183 185
184 SocketServer* socketserver() { return ss_; } 186 SocketServer* socketserver();
185 void set_socketserver(SocketServer* ss); 187 void set_socketserver(SocketServer* ss);
186 188
187 // Note: The behavior of MessageQueue has changed. When a MQ is stopped, 189 // Note: The behavior of MessageQueue has changed. When a MQ is stopped,
188 // futher Posts and Sends will fail. However, any pending Sends and *ready* 190 // futher Posts and Sends will fail. However, any pending Sends and *ready*
189 // Posts (as opposed to unexpired delayed Posts) will be delivered before 191 // Posts (as opposed to unexpired delayed Posts) will be delivered before
190 // Get (or Peek) returns false. By guaranteeing delivery of those messages, 192 // Get (or Peek) returns false. By guaranteeing delivery of those messages,
191 // we eliminate the race condition when an MessageHandler and MessageQueue 193 // we eliminate the race condition when an MessageHandler and MessageQueue
192 // may be destroyed independently of each other. 194 // may be destroyed independently of each other.
193 virtual void Quit(); 195 virtual void Quit();
194 virtual bool IsQuitting(); 196 virtual bool IsQuitting();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 MessageData* pdata); 255 MessageData* pdata);
254 256
255 // Perform initialization, subclasses must call this from their constructor 257 // Perform initialization, subclasses must call this from their constructor
256 // if false was passed as init_queue to the MessageQueue constructor. 258 // if false was passed as init_queue to the MessageQueue constructor.
257 void DoInit(); 259 void DoInit();
258 260
259 // Perform cleanup, subclasses that override Clear must call this from the 261 // Perform cleanup, subclasses that override Clear must call this from the
260 // destructor. 262 // destructor.
261 void DoDestroy(); 263 void DoDestroy();
262 264
263 // The SocketServer is not owned by MessageQueue. 265 void WakeUpSocketServer();
264 SocketServer* ss_; 266
265 // If a server isn't supplied in the constructor, use this one.
266 scoped_ptr<SocketServer> default_ss_;
267 bool fStop_; 267 bool fStop_;
268 bool fPeekKeep_; 268 bool fPeekKeep_;
269 Message msgPeek_; 269 Message msgPeek_;
270 MessageList msgq_; 270 MessageList msgq_ GUARDED_BY(crit_);
271 PriorityQueue dmsgq_; 271 PriorityQueue dmsgq_ GUARDED_BY(crit_);
272 uint32_t dmsgq_next_num_; 272 uint32_t dmsgq_next_num_ GUARDED_BY(crit_);
273 CriticalSection crit_; 273 CriticalSection crit_;
274 bool fInitialized_; 274 bool fInitialized_;
275 bool fDestroyed_; 275 bool fDestroyed_;
276 276
277 private: 277 private:
278 // The SocketServer is not owned by MessageQueue.
279 SocketServer* ss_ GUARDED_BY(ss_lock_);
280 // If a server isn't supplied in the constructor, use this one.
281 scoped_ptr<SocketServer> default_ss_;
282 SharedExclusiveLock ss_lock_;
283
278 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue); 284 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue);
279 }; 285 };
280 286
281 } // namespace rtc 287 } // namespace rtc
282 288
283 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ 289 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/messagequeue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698