| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 #endif | 109 #endif |
| 110 CritScope cs(&crit_); | 110 CritScope cs(&crit_); |
| 111 std::vector<MessageQueue *>::iterator iter; | 111 std::vector<MessageQueue *>::iterator iter; |
| 112 for (iter = message_queues_.begin(); iter != message_queues_.end(); iter++) | 112 for (iter = message_queues_.begin(); iter != message_queues_.end(); iter++) |
| 113 (*iter)->Clear(handler); | 113 (*iter)->Clear(handler); |
| 114 } | 114 } |
| 115 | 115 |
| 116 //------------------------------------------------------------------ | 116 //------------------------------------------------------------------ |
| 117 // MessageQueue | 117 // MessageQueue |
| 118 | 118 |
| 119 MessageQueue::MessageQueue(SocketServer* ss) | 119 MessageQueue::MessageQueue(SocketServer* ss, bool add_to_queue_manager) |
| 120 : ss_(ss), fStop_(false), fPeekKeep_(false), | 120 : ss_(ss), fStop_(false), fPeekKeep_(false), |
| 121 dmsgq_next_num_(0) { | 121 dmsgq_next_num_(0), fDestroyed_(false) { |
| 122 if (!ss_) { | 122 if (!ss_) { |
| 123 // Currently, MessageQueue holds a socket server, and is the base class for | 123 // Currently, MessageQueue holds a socket server, and is the base class for |
| 124 // Thread. It seems like it makes more sense for Thread to hold the socket | 124 // Thread. It seems like it makes more sense for Thread to hold the socket |
| 125 // server, and provide it to the MessageQueue, since the Thread controls | 125 // server, and provide it to the MessageQueue, since the Thread controls |
| 126 // the I/O model, and MQ is agnostic to those details. Anyway, this causes | 126 // the I/O model, and MQ is agnostic to those details. Anyway, this causes |
| 127 // messagequeue_unittest to depend on network libraries... yuck. | 127 // messagequeue_unittest to depend on network libraries... yuck. |
| 128 default_ss_.reset(new DefaultSocketServer()); | 128 default_ss_.reset(new DefaultSocketServer()); |
| 129 ss_ = default_ss_.get(); | 129 ss_ = default_ss_.get(); |
| 130 } | 130 } |
| 131 ss_->SetMessageQueue(this); | 131 ss_->SetMessageQueue(this); |
| 132 MessageQueueManager::Add(this); | 132 if (add_to_queue_manager) { |
| 133 MessageQueueManager::Add(this); |
| 134 } |
| 133 } | 135 } |
| 134 | 136 |
| 135 MessageQueue::~MessageQueue() { | 137 MessageQueue::~MessageQueue() { |
| 138 DoDestroy(); |
| 139 } |
| 140 |
| 141 void MessageQueue::DoDestroy() { |
| 142 if (fDestroyed_) { |
| 143 return; |
| 144 } |
| 145 |
| 146 fDestroyed_ = true; |
| 136 // The signal is done from here to ensure | 147 // The signal is done from here to ensure |
| 137 // that it always gets called when the queue | 148 // that it always gets called when the queue |
| 138 // is going away. | 149 // is going away. |
| 139 SignalQueueDestroyed(); | 150 SignalQueueDestroyed(); |
| 140 MessageQueueManager::Remove(this); | 151 MessageQueueManager::Remove(this); |
| 141 Clear(NULL); | 152 Clear(NULL); |
| 142 if (ss_) { | 153 if (ss_) { |
| 143 ss_->SetMessageQueue(NULL); | 154 ss_->SetMessageQueue(NULL); |
| 144 } | 155 } |
| 145 } | 156 } |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 414 } |
| 404 dmsgq_.container().erase(new_end, dmsgq_.container().end()); | 415 dmsgq_.container().erase(new_end, dmsgq_.container().end()); |
| 405 dmsgq_.reheap(); | 416 dmsgq_.reheap(); |
| 406 } | 417 } |
| 407 | 418 |
| 408 void MessageQueue::Dispatch(Message *pmsg) { | 419 void MessageQueue::Dispatch(Message *pmsg) { |
| 409 pmsg->phandler->OnMessage(pmsg); | 420 pmsg->phandler->OnMessage(pmsg); |
| 410 } | 421 } |
| 411 | 422 |
| 412 } // namespace rtc | 423 } // namespace rtc |
| OLD | NEW |