From 0f0bcb39f3fcb2b6185f146dfc4f4357276e40d4 Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Mon, 7 Dec 2020 11:45:55 +0000 Subject: [PATCH] Declare BaseChannel::media_channel_ const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it thread-safe to access, but not necessarily to use. Bug: webrtc:12230 Change-Id: I6b48d86dff24b162d382135abeaf560971fdf614 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/196524 Reviewed-by: Henrik Boström Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/master@{#32785} --- pc/channel.cc | 11 +++-------- pc/channel.h | 7 +------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/pc/channel.cc b/pc/channel.cc index 6ab43711b6..aad7c54381 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -152,17 +152,12 @@ BaseChannel::~BaseChannel() { // Eats any outstanding messages or packets. worker_thread_->Clear(&invoker_); worker_thread_->Clear(this); - // We must destroy the media channel before the transport channel, otherwise - // the media channel may try to send on the dead transport channel. NULLing - // is not an effective strategy since the sends will come on another thread. - media_channel_.reset(); - RTC_LOG(LS_INFO) << "Destroyed channel: " << ToString(); + // The media channel is destroyed at the end of the destructor, since it + // is a std::unique_ptr. The transport channel (rtp_transport) must outlive + // the media channel. } std::string BaseChannel::ToString() const { - // TODO(bugs.webrtc.org/12230): When media_channel_ is guarded by - // worker_thread(), rewrite this debug printout to not print the - // media type when called from non-worker-thread. rtc::StringBuilder sb; sb << "{mid: " << content_name_; if (media_channel_) { diff --git a/pc/channel.h b/pc/channel.h index ad75070c86..d9e6d9b728 100644 --- a/pc/channel.h +++ b/pc/channel.h @@ -185,9 +185,6 @@ class BaseChannel : public ChannelInterface, } MediaChannel* media_channel() const override { - // TODO(bugs.webrtc.org/12230): Called on multiple threads, - // including from StatsCollector::ExtractMediaInfo. - // RTC_DCHECK_RUN_ON(worker_thread()); return media_channel_.get(); } @@ -348,9 +345,7 @@ class BaseChannel : public ChannelInterface, // MediaChannel related members that should be accessed from the worker // thread. - // TODO(bugs.webrtc.org/12230): written on worker thread, accessed by - // multiple threads. - std::unique_ptr media_channel_; + const std::unique_ptr media_channel_; // Currently the |enabled_| flag is accessed from the signaling thread as // well, but it can be changed only when signaling thread does a synchronous // call to the worker thread, so it should be safe.