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 #include <algorithm> | 10 #include <algorithm> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const CriticalSection* const cs_; | 42 const CriticalSection* const cs_; |
43 bool* locked_; | 43 bool* locked_; |
44 | 44 |
45 RTC_DISALLOW_COPY_AND_ASSIGN(DebugNonReentrantCritScope); | 45 RTC_DISALLOW_COPY_AND_ASSIGN(DebugNonReentrantCritScope); |
46 }; | 46 }; |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 //------------------------------------------------------------------ | 49 //------------------------------------------------------------------ |
50 // MessageQueueManager | 50 // MessageQueueManager |
51 | 51 |
52 MessageQueueManager* MessageQueueManager::instance_ = NULL; | 52 MessageQueueManager* MessageQueueManager::instance_ = nullptr; |
53 | 53 |
54 MessageQueueManager* MessageQueueManager::Instance() { | 54 MessageQueueManager* MessageQueueManager::Instance() { |
55 // Note: This is not thread safe, but it is first called before threads are | 55 // Note: This is not thread safe, but it is first called before threads are |
56 // spawned. | 56 // spawned. |
57 if (!instance_) | 57 if (!instance_) |
58 instance_ = new MessageQueueManager; | 58 instance_ = new MessageQueueManager; |
59 return instance_; | 59 return instance_; |
60 } | 60 } |
61 | 61 |
62 bool MessageQueueManager::IsInitialized() { | 62 bool MessageQueueManager::IsInitialized() { |
63 return instance_ != NULL; | 63 return instance_ != nullptr; |
64 } | 64 } |
65 | 65 |
66 MessageQueueManager::MessageQueueManager() : locked_(false) {} | 66 MessageQueueManager::MessageQueueManager() : locked_(false) {} |
67 | 67 |
68 MessageQueueManager::~MessageQueueManager() { | 68 MessageQueueManager::~MessageQueueManager() { |
69 } | 69 } |
70 | 70 |
71 void MessageQueueManager::Add(MessageQueue *message_queue) { | 71 void MessageQueueManager::Add(MessageQueue *message_queue) { |
72 return Instance()->AddInternal(message_queue); | 72 return Instance()->AddInternal(message_queue); |
73 } | 73 } |
(...skipping 18 matching lines...) Expand all Loading... |
92 DebugNonReentrantCritScope cs(&crit_, &locked_); | 92 DebugNonReentrantCritScope cs(&crit_, &locked_); |
93 std::vector<MessageQueue *>::iterator iter; | 93 std::vector<MessageQueue *>::iterator iter; |
94 iter = std::find(message_queues_.begin(), message_queues_.end(), | 94 iter = std::find(message_queues_.begin(), message_queues_.end(), |
95 message_queue); | 95 message_queue); |
96 if (iter != message_queues_.end()) { | 96 if (iter != message_queues_.end()) { |
97 message_queues_.erase(iter); | 97 message_queues_.erase(iter); |
98 } | 98 } |
99 destroy = message_queues_.empty(); | 99 destroy = message_queues_.empty(); |
100 } | 100 } |
101 if (destroy) { | 101 if (destroy) { |
102 instance_ = NULL; | 102 instance_ = nullptr; |
103 delete this; | 103 delete this; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void MessageQueueManager::Clear(MessageHandler *handler) { | 107 void MessageQueueManager::Clear(MessageHandler *handler) { |
108 // If there isn't a message queue manager instance, then there aren't any | 108 // If there isn't a message queue manager instance, then there aren't any |
109 // queues to remove this handler from. | 109 // queues to remove this handler from. |
110 if (!instance_) return; | 110 if (!instance_) return; |
111 return Instance()->ClearInternal(handler); | 111 return Instance()->ClearInternal(handler); |
112 } | 112 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (fDestroyed_) { | 207 if (fDestroyed_) { |
208 return; | 208 return; |
209 } | 209 } |
210 | 210 |
211 fDestroyed_ = true; | 211 fDestroyed_ = true; |
212 // The signal is done from here to ensure | 212 // The signal is done from here to ensure |
213 // that it always gets called when the queue | 213 // that it always gets called when the queue |
214 // is going away. | 214 // is going away. |
215 SignalQueueDestroyed(); | 215 SignalQueueDestroyed(); |
216 MessageQueueManager::Remove(this); | 216 MessageQueueManager::Remove(this); |
217 Clear(NULL); | 217 Clear(nullptr); |
218 | 218 |
219 SharedScope ss(&ss_lock_); | 219 SharedScope ss(&ss_lock_); |
220 if (ss_) { | 220 if (ss_) { |
221 ss_->SetMessageQueue(NULL); | 221 ss_->SetMessageQueue(nullptr); |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 SocketServer* MessageQueue::socketserver() { | 225 SocketServer* MessageQueue::socketserver() { |
226 SharedScope ss(&ss_lock_); | 226 SharedScope ss(&ss_lock_); |
227 return ss_; | 227 return ss_; |
228 } | 228 } |
229 | 229 |
230 void MessageQueue::set_socketserver(SocketServer* ss) { | 230 void MessageQueue::set_socketserver(SocketServer* ss) { |
231 // Need to lock exclusively here to prevent simultaneous modifications from | 231 // Need to lock exclusively here to prevent simultaneous modifications from |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // Log a warning for time-sensitive messages that we're late to deliver. | 326 // Log a warning for time-sensitive messages that we're late to deliver. |
327 if (pmsg->ts_sensitive) { | 327 if (pmsg->ts_sensitive) { |
328 int64_t delay = TimeDiff(msCurrent, pmsg->ts_sensitive); | 328 int64_t delay = TimeDiff(msCurrent, pmsg->ts_sensitive); |
329 if (delay > 0) { | 329 if (delay > 0) { |
330 LOG_F(LS_WARNING) << "id: " << pmsg->message_id << " delay: " | 330 LOG_F(LS_WARNING) << "id: " << pmsg->message_id << " delay: " |
331 << (delay + kMaxMsgLatency) << "ms"; | 331 << (delay + kMaxMsgLatency) << "ms"; |
332 } | 332 } |
333 } | 333 } |
334 // If this was a dispose message, delete it and skip it. | 334 // If this was a dispose message, delete it and skip it. |
335 if (MQID_DISPOSE == pmsg->message_id) { | 335 if (MQID_DISPOSE == pmsg->message_id) { |
336 RTC_DCHECK(NULL == pmsg->phandler); | 336 RTC_DCHECK(nullptr == pmsg->phandler); |
337 delete pmsg->pdata; | 337 delete pmsg->pdata; |
338 *pmsg = Message(); | 338 *pmsg = Message(); |
339 continue; | 339 continue; |
340 } | 340 } |
341 return true; | 341 return true; |
342 } | 342 } |
343 | 343 |
344 if (IsQuitting()) | 344 if (IsQuitting()) |
345 break; | 345 break; |
346 | 346 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 pmsg->phandler->OnMessage(pmsg); | 538 pmsg->phandler->OnMessage(pmsg); |
539 int64_t end_time = TimeMillis(); | 539 int64_t end_time = TimeMillis(); |
540 int64_t diff = TimeDiff(end_time, start_time); | 540 int64_t diff = TimeDiff(end_time, start_time); |
541 if (diff >= kSlowDispatchLoggingThreshold) { | 541 if (diff >= kSlowDispatchLoggingThreshold) { |
542 LOG(LS_INFO) << "Message took " << diff << "ms to dispatch. Posted from: " | 542 LOG(LS_INFO) << "Message took " << diff << "ms to dispatch. Posted from: " |
543 << pmsg->posted_from.ToString(); | 543 << pmsg->posted_from.ToString(); |
544 } | 544 } |
545 } | 545 } |
546 | 546 |
547 } // namespace rtc | 547 } // namespace rtc |
OLD | NEW |