mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Delete MessageHandlerAutoCleanup and ThreadManager::Clear
Bug: webrtc:11988 Change-Id: Ic54d37fb802c9e55d417d65aa735fb07097d1b71 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/275768 Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38102}
This commit is contained in:
parent
9a6a087f37
commit
e16e3e2cb8
6 changed files with 0 additions and 98 deletions
|
@ -927,7 +927,6 @@ rtc_library("threading") {
|
|||
"async_resolver.h",
|
||||
"internal/default_socket_server.cc",
|
||||
"internal/default_socket_server.h",
|
||||
"message_handler.cc",
|
||||
"message_handler.h",
|
||||
"network_monitor.cc",
|
||||
"network_monitor.h",
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "rtc_base/message_handler.h"
|
||||
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
MessageHandlerAutoCleanup::MessageHandlerAutoCleanup() {}
|
||||
|
||||
MessageHandlerAutoCleanup::~MessageHandlerAutoCleanup() {
|
||||
// Note that even though this clears currently pending messages for the
|
||||
// message handler, it's still racy since it doesn't prevent threads that
|
||||
// might be in the process of posting new messages with would-be dangling
|
||||
// pointers.
|
||||
// This is related to the design of Message having a raw pointer.
|
||||
// We could consider whether it would be safer to require message handlers
|
||||
// to be reference counted (as some are).
|
||||
ThreadManager::Clear(this);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
|
@ -11,9 +11,6 @@
|
|||
#ifndef RTC_BASE_MESSAGE_HANDLER_H_
|
||||
#define RTC_BASE_MESSAGE_HANDLER_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "api/function_view.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
|
||||
namespace rtc {
|
||||
|
@ -27,23 +24,6 @@ class RTC_EXPORT MessageHandler {
|
|||
virtual void OnMessage(Message* msg) = 0;
|
||||
};
|
||||
|
||||
// Warning: Provided for backwards compatibility.
|
||||
//
|
||||
// This class performs expensive cleanup in the dtor that will affect all
|
||||
// instances of Thread (and their pending message queues) and will block the
|
||||
// current thread as well as all other threads.
|
||||
class RTC_EXPORT MessageHandlerAutoCleanup : public MessageHandler {
|
||||
public:
|
||||
~MessageHandlerAutoCleanup() override;
|
||||
|
||||
MessageHandlerAutoCleanup(const MessageHandlerAutoCleanup&) = delete;
|
||||
MessageHandlerAutoCleanup& operator=(const MessageHandlerAutoCleanup&) =
|
||||
delete;
|
||||
|
||||
protected:
|
||||
MessageHandlerAutoCleanup();
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_MESSAGE_HANDLER_H_
|
||||
|
|
|
@ -195,20 +195,6 @@ void ThreadManager::RegisterSendAndCheckForCycles(Thread* source,
|
|||
}
|
||||
#endif
|
||||
|
||||
// static
|
||||
void ThreadManager::Clear(MessageHandler* handler) {
|
||||
return Instance()->ClearInternal(handler);
|
||||
}
|
||||
void ThreadManager::ClearInternal(MessageHandler* handler) {
|
||||
// Deleted objects may cause re-entrant calls to ClearInternal. This is
|
||||
// allowed as the list of message queues does not change while queues are
|
||||
// cleared.
|
||||
MarkProcessingCritScope cs(&crit_, &processing_);
|
||||
for (Thread* queue : message_queues_) {
|
||||
queue->Clear(handler);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void ThreadManager::ProcessAllMessageQueuesForTesting() {
|
||||
return Instance()->ProcessAllMessageQueuesInternal();
|
||||
|
|
|
@ -89,7 +89,6 @@ class RTC_EXPORT ThreadManager {
|
|||
|
||||
static void Add(Thread* message_queue);
|
||||
static void Remove(Thread* message_queue);
|
||||
static void Clear(MessageHandler* handler);
|
||||
|
||||
// For testing purposes, for use with a simulated clock.
|
||||
// Ensures that all message queues have processed delayed messages
|
||||
|
@ -135,7 +134,6 @@ class RTC_EXPORT ThreadManager {
|
|||
void SetCurrentThreadInternal(Thread* thread);
|
||||
void AddInternal(Thread* message_queue);
|
||||
void RemoveInternal(Thread* message_queue);
|
||||
void ClearInternal(MessageHandler* handler);
|
||||
void ProcessAllMessageQueuesInternal();
|
||||
#if RTC_DCHECK_IS_ON
|
||||
void RemoveFromSendGraph(Thread* thread) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
||||
|
|
|
@ -579,37 +579,6 @@ TEST(ThreadManager, ProcessAllMessageQueuesWithClearedQueue) {
|
|||
ThreadManager::ProcessAllMessageQueuesForTesting();
|
||||
}
|
||||
|
||||
class RefCountedHandler : public MessageHandler, public rtc::RefCountInterface {
|
||||
public:
|
||||
~RefCountedHandler() override { ThreadManager::Clear(this); }
|
||||
|
||||
void OnMessage(Message* msg) override {}
|
||||
};
|
||||
|
||||
class EmptyHandler : public MessageHandler {
|
||||
public:
|
||||
~EmptyHandler() override { ThreadManager::Clear(this); }
|
||||
|
||||
void OnMessage(Message* msg) override {}
|
||||
};
|
||||
|
||||
TEST(ThreadManager, ClearReentrant) {
|
||||
std::unique_ptr<Thread> t(Thread::Create());
|
||||
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 "Thread::Clear".
|
||||
t->Post(RTC_FROM_HERE, inner_handler, 0);
|
||||
t->Post(RTC_FROM_HERE, &handler, 0,
|
||||
new ScopedRefMessageData<RefCountedHandler>(inner_handler));
|
||||
}
|
||||
|
||||
void WaitAndSetEvent(Event* wait_event, Event* set_event) {
|
||||
wait_event->Wait(Event::kForever);
|
||||
set_event->Set();
|
||||
|
|
Loading…
Reference in a new issue