| 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 |
| 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" | |
| 28 #include "webrtc/base/sigslot.h" | 27 #include "webrtc/base/sigslot.h" |
| 29 #include "webrtc/base/socketserver.h" | 28 #include "webrtc/base/socketserver.h" |
| 30 #include "webrtc/base/timeutils.h" | 29 #include "webrtc/base/timeutils.h" |
| 31 #include "webrtc/base/thread_annotations.h" | |
| 32 | 30 |
| 33 namespace rtc { | 31 namespace rtc { |
| 34 | 32 |
| 35 struct Message; | 33 struct Message; |
| 36 class MessageQueue; | 34 class MessageQueue; |
| 37 | 35 |
| 38 // MessageQueueManager does cleanup of of message queues | 36 // MessageQueueManager does cleanup of of message queues |
| 39 | 37 |
| 40 class MessageQueueManager { | 38 class MessageQueueManager { |
| 41 public: | 39 public: |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // being created. | 174 // being created. |
| 177 explicit MessageQueue(SocketServer* ss = NULL, | 175 explicit MessageQueue(SocketServer* ss = NULL, |
| 178 bool init_queue = true); | 176 bool init_queue = true); |
| 179 | 177 |
| 180 // NOTE: SUBCLASSES OF MessageQueue THAT OVERRIDE Clear MUST CALL | 178 // NOTE: SUBCLASSES OF MessageQueue THAT OVERRIDE Clear MUST CALL |
| 181 // DoDestroy() IN THEIR DESTRUCTORS! This is required to avoid a data race | 179 // DoDestroy() IN THEIR DESTRUCTORS! This is required to avoid a data race |
| 182 // between the destructor modifying the vtable, and the MessageQueueManager | 180 // between the destructor modifying the vtable, and the MessageQueueManager |
| 183 // calling Clear on the object from a different thread. | 181 // calling Clear on the object from a different thread. |
| 184 virtual ~MessageQueue(); | 182 virtual ~MessageQueue(); |
| 185 | 183 |
| 186 SocketServer* socketserver(); | 184 SocketServer* socketserver() { return ss_; } |
| 187 void set_socketserver(SocketServer* ss); | 185 void set_socketserver(SocketServer* ss); |
| 188 | 186 |
| 189 // 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, |
| 190 // 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* |
| 191 // Posts (as opposed to unexpired delayed Posts) will be delivered before | 189 // Posts (as opposed to unexpired delayed Posts) will be delivered before |
| 192 // Get (or Peek) returns false. By guaranteeing delivery of those messages, | 190 // Get (or Peek) returns false. By guaranteeing delivery of those messages, |
| 193 // we eliminate the race condition when an MessageHandler and MessageQueue | 191 // we eliminate the race condition when an MessageHandler and MessageQueue |
| 194 // may be destroyed independently of each other. | 192 // may be destroyed independently of each other. |
| 195 virtual void Quit(); | 193 virtual void Quit(); |
| 196 virtual bool IsQuitting(); | 194 virtual bool IsQuitting(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 MessageData* pdata); | 253 MessageData* pdata); |
| 256 | 254 |
| 257 // Perform initialization, subclasses must call this from their constructor | 255 // Perform initialization, subclasses must call this from their constructor |
| 258 // if false was passed as init_queue to the MessageQueue constructor. | 256 // if false was passed as init_queue to the MessageQueue constructor. |
| 259 void DoInit(); | 257 void DoInit(); |
| 260 | 258 |
| 261 // Perform cleanup, subclasses that override Clear must call this from the | 259 // Perform cleanup, subclasses that override Clear must call this from the |
| 262 // destructor. | 260 // destructor. |
| 263 void DoDestroy(); | 261 void DoDestroy(); |
| 264 | 262 |
| 265 void WakeUpSocketServer(); | 263 // The SocketServer is not owned by MessageQueue. |
| 266 | 264 SocketServer* ss_; |
| 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_ GUARDED_BY(crit_); | 270 MessageList msgq_; |
| 271 PriorityQueue dmsgq_ GUARDED_BY(crit_); | 271 PriorityQueue dmsgq_; |
| 272 uint32_t dmsgq_next_num_ GUARDED_BY(crit_); | 272 uint32_t dmsgq_next_num_; |
| 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 | |
| 284 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue); | 278 RTC_DISALLOW_COPY_AND_ASSIGN(MessageQueue); |
| 285 }; | 279 }; |
| 286 | 280 |
| 287 } // namespace rtc | 281 } // namespace rtc |
| 288 | 282 |
| 289 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ | 283 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ |
| OLD | NEW |