OLD | NEW |
---|---|
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 Loading... | |
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 should pass false for add_to_queue_manager and | |
172 // call MessageQueueManager::Add from their constructor to prevent races | |
173 // between the MessageQueueManager already using the object while the vtable | |
174 // is still being created. | |
175 explicit MessageQueue(SocketServer* ss = NULL, | |
176 bool add_to_queue_manager = true); | |
Taylor Brandstetter
2016/02/04 19:16:38
Instead of the "add_to_queue_manager" approach, wh
joachim
2016/02/04 20:22:31
Hmm, wouldn't that be the same race as before if b
Taylor Brandstetter
2016/02/04 21:05:58
You're right; I wasn't thinking straight...
joachim
2016/02/04 22:54:08
I think I'll leave it at "init_queue" even for the
| |
177 | |
178 // NOTE: ALL SUBCLASSES OF MessageQueue MUST CALL DoDestroy() IN THEIR | |
179 // DESTRUCTORS! This is required to avoid a data race between the destructor | |
180 // modifying the vtable, and the MessageQueue being removed from the | |
181 // MessageQueueManager. | |
Taylor Brandstetter
2016/02/04 19:16:38
Isn't it more of a race between the MessageQueue b
joachim
2016/02/04 20:22:31
Right, I updated the comment.
| |
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 Loading... | |
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 cleanup, subclasses must call this from the destructor. | |
256 void DoDestroy(); | |
257 | |
244 // The SocketServer is not owned by MessageQueue. | 258 // The SocketServer is not owned by MessageQueue. |
245 SocketServer* ss_; | 259 SocketServer* ss_; |
246 // If a server isn't supplied in the constructor, use this one. | 260 // If a server isn't supplied in the constructor, use this one. |
247 scoped_ptr<SocketServer> default_ss_; | 261 scoped_ptr<SocketServer> default_ss_; |
248 bool fStop_; | 262 bool fStop_; |
249 bool fPeekKeep_; | 263 bool fPeekKeep_; |
250 Message msgPeek_; | 264 Message msgPeek_; |
251 MessageList msgq_; | 265 MessageList msgq_; |
252 PriorityQueue dmsgq_; | 266 PriorityQueue dmsgq_; |
253 uint32_t dmsgq_next_num_; | 267 uint32_t dmsgq_next_num_; |
254 CriticalSection crit_; | 268 CriticalSection crit_; |
269 bool fDestroyed_; | |
255 | 270 |
256 private: | 271 private: |
257 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue); | 272 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue); |
258 }; | 273 }; |
259 | 274 |
260 } // namespace rtc | 275 } // namespace rtc |
261 | 276 |
262 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ | 277 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ |
OLD | NEW |