From 142104183d79c33cee52e8caa0e09914e0135233 Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Fri, 17 Jun 2022 17:29:03 +0900 Subject: [PATCH] Disallow invokes from network thread to itself https://webrtc-review.googlesource.com/c/src/+/265060 removed the last case the network thread invokes itself, now we can use DisallowAllInvokes on the network thread. Bug: webrtc:12802 Change-Id: I262d65bb557e2976bab5b0d9e73756222b4e02ef Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266100 Commit-Queue: Daniel.L (Byoungchan) Lee Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#37251} --- pc/connection_context.cc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pc/connection_context.cc b/pc/connection_context.cc index 29af2c8189..27bc822a4e 100644 --- a/pc/connection_context.cc +++ b/pc/connection_context.cc @@ -12,6 +12,7 @@ #include #include +#include #include "api/task_queue/to_queued_task.h" #include "api/transport/field_trial_based_config.h" @@ -106,21 +107,25 @@ ConnectionContext::ConnectionContext( MaybeCreateSctpFactory(std::move(dependencies->sctp_factory), network_thread(), *trials_.get())) { + RTC_DCHECK_RUN_ON(signaling_thread_); signaling_thread_->AllowInvokesToThread(worker_thread()); signaling_thread_->AllowInvokesToThread(network_thread_); worker_thread_->AllowInvokesToThread(network_thread_); - if (network_thread_->IsCurrent()) { - // TODO(https://crbug.com/webrtc/12802) switch to DisallowAllInvokes - network_thread_->AllowInvokesToThread(network_thread_); - } else { - network_thread_->PostTask(ToQueuedTask([thread = network_thread_] { - thread->DisallowBlockingCalls(); - // TODO(https://crbug.com/webrtc/12802) switch to DisallowAllInvokes - thread->AllowInvokesToThread(thread); - })); + if (!network_thread_->IsCurrent()) { + // network_thread_->IsCurrent() == true means signaling_thread_ is + // network_thread_. In this case, no further action is required as + // signaling_thread_ can already invoke network_thread_. + network_thread_->PostTask(ToQueuedTask( + [thread = network_thread_, worker_thread = worker_thread_.get()] { + thread->DisallowBlockingCalls(); + thread->DisallowAllInvokes(); + if (worker_thread == thread) { + // In this case, worker_thread_ == network_thread_ + thread->AllowInvokesToThread(thread); + } + })); } - RTC_DCHECK_RUN_ON(signaling_thread_); rtc::InitRandom(rtc::Time32()); rtc::SocketFactory* socket_factory = dependencies->socket_factory;