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 19 matching lines...) Expand all Loading... |
30 #include "webrtc/base/timeutils.h" | 30 #include "webrtc/base/timeutils.h" |
31 #include "webrtc/base/thread_annotations.h" | 31 #include "webrtc/base/thread_annotations.h" |
32 | 32 |
33 namespace rtc { | 33 namespace rtc { |
34 | 34 |
35 struct Message; | 35 struct Message; |
36 class MessageQueue; | 36 class MessageQueue; |
37 | 37 |
38 // MessageQueueManager does cleanup of of message queues | 38 // MessageQueueManager does cleanup of of message queues |
39 | 39 |
40 class MessageQueueManager { | 40 class MessageQueueManager : public MessageHandler { |
41 public: | 41 public: |
42 static void Add(MessageQueue *message_queue); | 42 static void Add(MessageQueue *message_queue); |
43 static void Remove(MessageQueue *message_queue); | 43 static void Remove(MessageQueue *message_queue); |
44 static void Clear(MessageHandler *handler); | 44 static void Clear(MessageHandler *handler); |
45 | 45 |
46 // For testing purposes, we expose whether or not the MessageQueueManager | 46 // For testing purposes, we expose whether or not the MessageQueueManager |
47 // instance has been initialized. It has no other use relative to the rest of | 47 // instance has been initialized. It has no other use relative to the rest of |
48 // the functions of this class, which auto-initialize the underlying | 48 // the functions of this class, which auto-initialize the underlying |
49 // MessageQueueManager instance when necessary. | 49 // MessageQueueManager instance when necessary. |
50 static bool IsInitialized(); | 50 static bool IsInitialized(); |
51 | 51 |
| 52 // Mainly for testing purposes, for use with a simulated clock. |
| 53 // Posts a no-op event on all message queues so they will wake from the |
| 54 // socket server select() and process messages again. |
| 55 static void WakeAllMessageQueues(); |
| 56 |
52 private: | 57 private: |
53 static MessageQueueManager* Instance(); | 58 static MessageQueueManager* Instance(); |
54 | 59 |
55 MessageQueueManager(); | 60 MessageQueueManager(); |
56 ~MessageQueueManager(); | 61 ~MessageQueueManager() override; |
57 | 62 |
58 void AddInternal(MessageQueue *message_queue); | 63 void AddInternal(MessageQueue *message_queue); |
59 void RemoveInternal(MessageQueue *message_queue); | 64 void RemoveInternal(MessageQueue *message_queue); |
60 void ClearInternal(MessageHandler *handler); | 65 void ClearInternal(MessageHandler *handler); |
| 66 void WakeAllMessageQueuesInternal(); |
| 67 void OnMessage(Message* pmsg) override; |
61 | 68 |
62 static MessageQueueManager* instance_; | 69 static MessageQueueManager* instance_; |
63 // This list contains all live MessageQueues. | 70 // This list contains all live MessageQueues. |
64 std::vector<MessageQueue *> message_queues_; | 71 std::vector<MessageQueue *> message_queues_; |
65 CriticalSection crit_; | 72 CriticalSection crit_; |
66 }; | 73 }; |
67 | 74 |
68 // Derive from this for specialized data | 75 // Derive from this for specialized data |
69 // App manages lifetime, except when messages are purged | 76 // App manages lifetime, except when messages are purged |
70 | 77 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // Used if SocketServer ownership lies with |this|. | 296 // Used if SocketServer ownership lies with |this|. |
290 std::unique_ptr<SocketServer> own_ss_; | 297 std::unique_ptr<SocketServer> own_ss_; |
291 SharedExclusiveLock ss_lock_; | 298 SharedExclusiveLock ss_lock_; |
292 | 299 |
293 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); | 300 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(MessageQueue); |
294 }; | 301 }; |
295 | 302 |
296 } // namespace rtc | 303 } // namespace rtc |
297 | 304 |
298 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ | 305 #endif // WEBRTC_BASE_MESSAGEQUEUE_H_ |
OLD | NEW |