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> |
11 | 11 |
12 #include "webrtc/base/checks.h" | 12 #include "webrtc/base/checks.h" |
13 #include "webrtc/base/common.h" | 13 #include "webrtc/base/common.h" |
14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
15 #include "webrtc/base/messagequeue.h" | 15 #include "webrtc/base/messagequeue.h" |
16 #include "webrtc/base/trace_event.h" | 16 #include "webrtc/base/trace_event.h" |
17 | 17 |
| 18 namespace { |
| 19 |
| 20 enum { MSG_WAKE_MESSAGE_QUEUE = 1 }; |
| 21 } |
| 22 |
18 namespace rtc { | 23 namespace rtc { |
19 | 24 |
20 const int kMaxMsgLatency = 150; // 150 ms | 25 const int kMaxMsgLatency = 150; // 150 ms |
21 | 26 |
22 //------------------------------------------------------------------ | 27 //------------------------------------------------------------------ |
23 // MessageQueueManager | 28 // MessageQueueManager |
24 | 29 |
25 MessageQueueManager* MessageQueueManager::instance_ = NULL; | 30 MessageQueueManager* MessageQueueManager::instance_ = NULL; |
26 | 31 |
27 MessageQueueManager* MessageQueueManager::Instance() { | 32 MessageQueueManager* MessageQueueManager::Instance() { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 void MessageQueueManager::ClearInternal(MessageHandler *handler) { | 101 void MessageQueueManager::ClearInternal(MessageHandler *handler) { |
97 #if CS_DEBUG_CHECKS // CurrentThreadIsOwner returns true by default. | 102 #if CS_DEBUG_CHECKS // CurrentThreadIsOwner returns true by default. |
98 ASSERT(!crit_.CurrentThreadIsOwner()); // See note above. | 103 ASSERT(!crit_.CurrentThreadIsOwner()); // See note above. |
99 #endif | 104 #endif |
100 CritScope cs(&crit_); | 105 CritScope cs(&crit_); |
101 std::vector<MessageQueue *>::iterator iter; | 106 std::vector<MessageQueue *>::iterator iter; |
102 for (iter = message_queues_.begin(); iter != message_queues_.end(); iter++) | 107 for (iter = message_queues_.begin(); iter != message_queues_.end(); iter++) |
103 (*iter)->Clear(handler); | 108 (*iter)->Clear(handler); |
104 } | 109 } |
105 | 110 |
| 111 void MessageQueueManager::WakeAllMessageQueues() { |
| 112 if (!instance_) { |
| 113 return; |
| 114 } |
| 115 return Instance()->WakeAllMessageQueuesInternal(); |
| 116 } |
| 117 |
| 118 void MessageQueueManager::WakeAllMessageQueuesInternal() { |
| 119 #if CS_DEBUG_CHECKS // CurrentThreadIsOwner returns true by default. |
| 120 ASSERT(!crit_.CurrentThreadIsOwner()); // See note above. |
| 121 #endif |
| 122 CritScope cs(&crit_); |
| 123 for (MessageQueue* queue : message_queues_) { |
| 124 // Posting an arbitrary message will force the message queue to wake up. |
| 125 queue->Post(this, MSG_WAKE_MESSAGE_QUEUE); |
| 126 } |
| 127 } |
| 128 |
| 129 void MessageQueueManager::OnMessage(Message* pmsg) { |
| 130 RTC_DCHECK(pmsg->message_id == MSG_WAKE_MESSAGE_QUEUE); |
| 131 } |
| 132 |
106 //------------------------------------------------------------------ | 133 //------------------------------------------------------------------ |
107 // MessageQueue | 134 // MessageQueue |
108 MessageQueue::MessageQueue(SocketServer* ss, bool init_queue) | 135 MessageQueue::MessageQueue(SocketServer* ss, bool init_queue) |
109 : fStop_(false), fPeekKeep_(false), | 136 : fStop_(false), fPeekKeep_(false), |
110 dmsgq_next_num_(0), fInitialized_(false), fDestroyed_(false), ss_(ss) { | 137 dmsgq_next_num_(0), fInitialized_(false), fDestroyed_(false), ss_(ss) { |
111 RTC_DCHECK(ss); | 138 RTC_DCHECK(ss); |
112 // Currently, MessageQueue holds a socket server, and is the base class for | 139 // Currently, MessageQueue holds a socket server, and is the base class for |
113 // Thread. It seems like it makes more sense for Thread to hold the socket | 140 // Thread. It seems like it makes more sense for Thread to hold the socket |
114 // server, and provide it to the MessageQueue, since the Thread controls | 141 // server, and provide it to the MessageQueue, since the Thread controls |
115 // the I/O model, and MQ is agnostic to those details. Anyway, this causes | 142 // the I/O model, and MQ is agnostic to those details. Anyway, this causes |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 dmsgq_.container().erase(new_end, dmsgq_.container().end()); | 477 dmsgq_.container().erase(new_end, dmsgq_.container().end()); |
451 dmsgq_.reheap(); | 478 dmsgq_.reheap(); |
452 } | 479 } |
453 | 480 |
454 void MessageQueue::Dispatch(Message *pmsg) { | 481 void MessageQueue::Dispatch(Message *pmsg) { |
455 TRACE_EVENT0("webrtc", "MessageQueue::Dispatch"); | 482 TRACE_EVENT0("webrtc", "MessageQueue::Dispatch"); |
456 pmsg->phandler->OnMessage(pmsg); | 483 pmsg->phandler->OnMessage(pmsg); |
457 } | 484 } |
458 | 485 |
459 } // namespace rtc | 486 } // namespace rtc |
OLD | NEW |