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

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

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 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
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 int cmsDelay_; // for debugging 160 int cmsDelay_; // for debugging
161 uint32_t msTrigger_; 161 uint32_t msTrigger_;
162 uint32_t num_; 162 uint32_t num_;
163 Message msg_; 163 Message msg_;
164 }; 164 };
165 165
166 class MessageQueue { 166 class MessageQueue {
167 public: 167 public:
168 static const int kForever = -1; 168 static const int kForever = -1;
169 169
170 explicit MessageQueue(SocketServer* ss = NULL); 170 // Create a new MessageQueue and optionally assign it to the passed
171 // SocketServer. Subclasses that override Clear should pass false for
172 // init_queue and call DoInit() from their constructor to prevent races
173 // with the MessageQueueManager using the object while the vtable is still
174 // being created.
175 explicit MessageQueue(SocketServer* ss = NULL,
176 bool init_queue = true);
177
178 // NOTE: SUBCLASSES OF MessageQueue THAT OVERRIDE Clear MUST CALL
179 // DoDestroy() IN THEIR DESTRUCTORS! This is required to avoid a data race
180 // between the destructor modifying the vtable, and the MessageQueueManager
181 // calling Clear on the object from a different thread.
171 virtual ~MessageQueue(); 182 virtual ~MessageQueue();
172 183
173 SocketServer* socketserver() { return ss_; } 184 SocketServer* socketserver() { return ss_; }
174 void set_socketserver(SocketServer* ss); 185 void set_socketserver(SocketServer* ss);
175 186
176 // Note: The behavior of MessageQueue has changed. When a MQ is stopped, 187 // Note: The behavior of MessageQueue has changed. When a MQ is stopped,
177 // futher Posts and Sends will fail. However, any pending Sends and *ready* 188 // futher Posts and Sends will fail. However, any pending Sends and *ready*
178 // Posts (as opposed to unexpired delayed Posts) will be delivered before 189 // Posts (as opposed to unexpired delayed Posts) will be delivered before
179 // Get (or Peek) returns false. By guaranteeing delivery of those messages, 190 // Get (or Peek) returns false. By guaranteeing delivery of those messages,
180 // we eliminate the race condition when an MessageHandler and MessageQueue 191 // we eliminate the race condition when an MessageHandler and MessageQueue
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 container_type& container() { return c; } 245 container_type& container() { return c; }
235 void reheap() { make_heap(c.begin(), c.end(), comp); } 246 void reheap() { make_heap(c.begin(), c.end(), comp); }
236 }; 247 };
237 248
238 void DoDelayPost(int cmsDelay, 249 void DoDelayPost(int cmsDelay,
239 uint32_t tstamp, 250 uint32_t tstamp,
240 MessageHandler* phandler, 251 MessageHandler* phandler,
241 uint32_t id, 252 uint32_t id,
242 MessageData* pdata); 253 MessageData* pdata);
243 254
255 // Perform initialization, subclasses must call this from their constructor
256 // if false was passed as init_queue to the MessageQueue constructor.
257 void DoInit();
258
259 // Perform cleanup, subclasses that override Clear must call this from the
260 // destructor.
261 void DoDestroy();
262
244 // The SocketServer is not owned by MessageQueue. 263 // The SocketServer is not owned by MessageQueue.
245 SocketServer* ss_; 264 SocketServer* ss_;
246 // If a server isn't supplied in the constructor, use this one. 265 // If a server isn't supplied in the constructor, use this one.
247 scoped_ptr<SocketServer> default_ss_; 266 scoped_ptr<SocketServer> default_ss_;
248 bool fStop_; 267 bool fStop_;
249 bool fPeekKeep_; 268 bool fPeekKeep_;
250 Message msgPeek_; 269 Message msgPeek_;
251 MessageList msgq_; 270 MessageList msgq_;
252 PriorityQueue dmsgq_; 271 PriorityQueue dmsgq_;
253 uint32_t dmsgq_next_num_; 272 uint32_t dmsgq_next_num_;
254 CriticalSection crit_; 273 CriticalSection crit_;
274 bool fInitialized_;
275 bool fDestroyed_;
255 276
256 private: 277 private:
257 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue); 278 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue);
258 }; 279 };
259 280
260 } // namespace rtc 281 } // namespace rtc
261 282
262 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ 283 #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