Use function-local static variable for MessageQueueManager singleton.
Rely on C++11 thread-safe initialization on first call to
MessageQueueManager::Instance(), in the same way as for
ThreadManager::Instance().
Bug: None
Change-Id: I26244f90c5d7f94a2454688297f55bf96617e78c
Reviewed-on: https://webrtc-review.googlesource.com/97721
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24625}
diff --git a/rtc_base/messagequeue.h b/rtc_base/messagequeue.h
index d64ea86..e7e4792 100644
--- a/rtc_base/messagequeue.h
+++ b/rtc_base/messagequeue.h
@@ -43,12 +43,6 @@
static void Remove(MessageQueue* message_queue);
static void Clear(MessageHandler* handler);
- // For testing purposes, we expose whether or not the MessageQueueManager
- // instance has been initialized. It has no other use relative to the rest of
- // the functions of this class, which auto-initialize the underlying
- // MessageQueueManager instance when necessary.
- static bool IsInitialized();
-
// TODO(nisse): Delete alias, as soon as downstream code is updated.
static void ProcessAllMessageQueues() { ProcessAllMessageQueuesForTesting(); }
@@ -68,7 +62,6 @@
void ClearInternal(MessageHandler* handler);
void ProcessAllMessageQueuesInternal();
- static MessageQueueManager* instance_;
// This list contains all live MessageQueues.
std::vector<MessageQueue*> message_queues_ RTC_GUARDED_BY(crit_);
@@ -305,9 +298,15 @@
// if false was passed as init_queue to the MessageQueue constructor.
void DoInit();
- // Perform cleanup, subclasses that override Clear must call this from the
- // destructor.
- void DoDestroy();
+ // Does not take any lock. Must be called either while holding crit_, or by
+ // the destructor (by definition, the latter has exclusive access).
+ void ClearInternal(MessageHandler* phandler,
+ uint32_t id,
+ MessageList* removed) RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_);
+
+ // Perform cleanup; subclasses must call this from the destructor,
+ // and are not expected to actually hold the lock.
+ void DoDestroy() RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_);
void WakeUpSocketServer();