From 2ba941e6bc1d20acb9cfda4b87ba53c80640bbcb Mon Sep 17 00:00:00 2001 From: Markus Handell Date: Tue, 20 Dec 2022 11:04:37 +0100 Subject: [PATCH] ConnectionContext: remove media engine without blocking. Bug: webrtc:14449 Change-Id: I445114c14f4d440a5a8cac003266047fe4588dab Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288580 Reviewed-by: Harald Alvestrand Commit-Queue: Markus Handell Cr-Commit-Position: refs/heads/main@{#38928} --- pc/connection_context.cc | 11 ++--------- pc/connection_context.h | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/pc/connection_context.cc b/pc/connection_context.cc index ec6f21cc13..d048218cb9 100644 --- a/pc/connection_context.cc +++ b/pc/connection_context.cc @@ -173,15 +173,8 @@ ConnectionContext::ConnectionContext( ConnectionContext::~ConnectionContext() { RTC_DCHECK_RUN_ON(signaling_thread_); - worker_thread_->BlockingCall([&] { - RTC_DCHECK_RUN_ON(worker_thread()); - // While `media_engine_` is const throughout the ConnectionContext's - // lifetime, it requires destruction to happen on the worker thread. Instead - // of marking the pointer as non-const, we live with this const_cast<> in - // the destructor. - const_cast&>(media_engine_) - .reset(); - }); + // `media_engine_` requires destruction to happen on the worker thread. + worker_thread_->PostTask([media_engine = std::move(media_engine_)] {}); // Make sure `worker_thread()` and `signaling_thread()` outlive // `default_socket_factory_` and `default_network_manager_`. diff --git a/pc/connection_context.h b/pc/connection_context.h index 0fe20c7890..44fc4878e7 100644 --- a/pc/connection_context.h +++ b/pc/connection_context.h @@ -122,7 +122,7 @@ class ConnectionContext final // Accessed both on signaling thread and worker thread. std::unique_ptr const trials_; - const std::unique_ptr media_engine_; + std::unique_ptr media_engine_; // This object should be used to generate any SSRC that is not explicitly // specified by the user (or by the remote party).