Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: webrtc/rtc_base/messagequeue_unittest.cc

Issue 2968753002: Support re-entrant calls to MessageQueueManager::Clear. (Closed)
Patch Set: Also Post inner handler to verify re-entrant clearing in the message queue works. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/rtc_base/messagequeue.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/rtc_base/messagequeue_unittest.cc
diff --git a/webrtc/rtc_base/messagequeue_unittest.cc b/webrtc/rtc_base/messagequeue_unittest.cc
index 78bcfcbea9abbf6070285dde1dc73d9f81cb2ccd..e31adf954992740017837696725ff61f12cf090f 100644
--- a/webrtc/rtc_base/messagequeue_unittest.cc
+++ b/webrtc/rtc_base/messagequeue_unittest.cc
@@ -18,6 +18,8 @@
#include "webrtc/rtc_base/gunit.h"
#include "webrtc/rtc_base/logging.h"
#include "webrtc/rtc_base/nullsocketserver.h"
+#include "webrtc/rtc_base/refcount.h"
+#include "webrtc/rtc_base/refcountedobject.h"
#include "webrtc/rtc_base/thread.h"
#include "webrtc/rtc_base/timeutils.h"
@@ -215,3 +217,32 @@ TEST(MessageQueueManager, ProcessAllMessageQueuesWithClearedQueue) {
rtc::Thread::Current()->Post(RTC_FROM_HERE, &event_signaler);
MessageQueueManager::ProcessAllMessageQueues();
}
+
+class RefCountedHandler
+ : public MessageHandler,
+ public rtc::RefCountInterface {
+ public:
+ void OnMessage(Message* msg) override {}
+};
+
+class EmptyHandler : public MessageHandler {
+ public:
+ void OnMessage(Message* msg) override {}
+};
+
+TEST(MessageQueueManager, ClearReentrant) {
+ Thread t;
+ EmptyHandler handler;
+ RefCountedHandler* inner_handler(
+ new rtc::RefCountedObject<RefCountedHandler>());
+ // When the empty handler is destroyed, it will clear messages queued for
+ // itself. The message to be cleared itself wraps a MessageHandler object
+ // (RefCountedHandler) so this will cause the message queue to be cleared
+ // again in a re-entrant fashion, which previously triggered a DCHECK.
+ // The inner handler will be removed in a re-entrant fashion from the
+ // message queue of the thread while the outer handler is removed, verifying
+ // that the iterator is not invalidated in "MessageQueue::Clear".
+ t.Post(RTC_FROM_HERE, inner_handler, 0);
+ t.Post(RTC_FROM_HERE, &handler, 0,
+ new ScopedRefMessageData<RefCountedHandler>(inner_handler));
+}
« no previous file with comments | « webrtc/rtc_base/messagequeue.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698