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 init_queue) |
120 : ss_(ss), fStop_(false), fPeekKeep_(false), | 120 : ss_(ss), fStop_(false), fPeekKeep_(false), |
121 dmsgq_next_num_(0) { | 121 dmsgq_next_num_(0), fInitialized_(false), 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 if (init_queue) { |
| 133 DoInit(); |
| 134 } |
| 135 } |
| 136 |
| 137 MessageQueue::~MessageQueue() { |
| 138 DoDestroy(); |
| 139 } |
| 140 |
| 141 void MessageQueue::DoInit() { |
| 142 if (fInitialized_) { |
| 143 return; |
| 144 } |
| 145 |
| 146 fInitialized_ = true; |
132 MessageQueueManager::Add(this); | 147 MessageQueueManager::Add(this); |
133 } | 148 } |
134 | 149 |
135 MessageQueue::~MessageQueue() { | 150 void MessageQueue::DoDestroy() { |
| 151 if (fDestroyed_) { |
| 152 return; |
| 153 } |
| 154 |
| 155 fDestroyed_ = true; |
136 // The signal is done from here to ensure | 156 // The signal is done from here to ensure |
137 // that it always gets called when the queue | 157 // that it always gets called when the queue |
138 // is going away. | 158 // is going away. |
139 SignalQueueDestroyed(); | 159 SignalQueueDestroyed(); |
140 MessageQueueManager::Remove(this); | 160 MessageQueueManager::Remove(this); |
141 Clear(NULL); | 161 Clear(NULL); |
142 if (ss_) { | 162 if (ss_) { |
143 ss_->SetMessageQueue(NULL); | 163 ss_->SetMessageQueue(NULL); |
144 } | 164 } |
145 } | 165 } |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 } | 423 } |
404 dmsgq_.container().erase(new_end, dmsgq_.container().end()); | 424 dmsgq_.container().erase(new_end, dmsgq_.container().end()); |
405 dmsgq_.reheap(); | 425 dmsgq_.reheap(); |
406 } | 426 } |
407 | 427 |
408 void MessageQueue::Dispatch(Message *pmsg) { | 428 void MessageQueue::Dispatch(Message *pmsg) { |
409 pmsg->phandler->OnMessage(pmsg); | 429 pmsg->phandler->OnMessage(pmsg); |
410 } | 430 } |
411 | 431 |
412 } // namespace rtc | 432 } // namespace rtc |
OLD | NEW |