From 98d26df5b78d16ff8a7e8517861254536736fe12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Mon, 7 Feb 2022 10:35:29 +0100 Subject: [PATCH] Reland "Delete NO_MAIN_THREAD_WRAPPING preprocessor define." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a reland of 0f78c6b28dbc0c9caa555ce89ce91b0f08c510ea Original change's description: > Delete NO_MAIN_THREAD_WRAPPING preprocessor define. > > Since many tests rely on rtc::Thread::Current(), add an > explicit rtc::AutoThread in the main() function used by tests. > > Bug: webrtc:9714 > Change-Id: Id82121967c9621fe1c2945846009c48139fa57da > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/39680 > Reviewed-by: Kári Helgason > Reviewed-by: Karl Wiberg > Commit-Queue: Niels Moller > Cr-Commit-Position: refs/heads/master@{#28000} Bug: webrtc:9714 Change-Id: I85f8a7058387771a31c099b1080ae53f1648dce6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/137513 Reviewed-by: Mirko Bonadei Reviewed-by: Tomas Gunnarsson Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/main@{#35932} --- rtc_base/BUILD.gn | 8 -------- rtc_base/thread.cc | 17 ++--------------- rtc_base/thread.h | 5 ----- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 53987743d2..f5a1c9548b 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -14,10 +14,6 @@ if (is_android) { import("//build/config/android/rules.gni") } -config("threading_chromium_config") { - defines = [ "NO_MAIN_THREAD_WRAPPING" ] -} - if (!rtc_build_ssl) { config("external_ssl_library") { assert(rtc_ssl_root != "", @@ -768,10 +764,6 @@ rtc_source_set("socket_server") { rtc_library("threading") { visibility = [ "*" ] - if (build_with_chromium) { - public_configs = [ ":threading_chromium_config" ] - } - sources = [ "async_resolver.cc", "async_resolver.h", diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc index c1c2c1bb4b..307d499255 100644 --- a/rtc_base/thread.cc +++ b/rtc_base/thread.cc @@ -255,19 +255,11 @@ Thread* Thread::Current() { ThreadManager* manager = ThreadManager::Instance(); Thread* thread = manager->CurrentThread(); -#ifndef NO_MAIN_THREAD_WRAPPING - // Only autowrap the thread which instantiated the ThreadManager. - if (!thread && manager->IsMainThread()) { - thread = new Thread(CreateDefaultSocketServer()); - thread->WrapCurrentWithThreadManager(manager, true); - } -#endif - return thread; } #if defined(WEBRTC_POSIX) -ThreadManager::ThreadManager() : main_thread_ref_(CurrentThreadRef()) { +ThreadManager::ThreadManager() { #if defined(WEBRTC_MAC) InitCocoaMultiThreading(); #endif @@ -284,8 +276,7 @@ void ThreadManager::SetCurrentThreadInternal(Thread* thread) { #endif #if defined(WEBRTC_WIN) -ThreadManager::ThreadManager() - : key_(TlsAlloc()), main_thread_ref_(CurrentThreadRef()) {} +ThreadManager::ThreadManager() : key_(TlsAlloc()) {} Thread* ThreadManager::CurrentThread() { return static_cast(TlsGetValue(key_)); @@ -341,10 +332,6 @@ void ThreadManager::UnwrapCurrentThread() { } } -bool ThreadManager::IsMainThread() { - return IsThreadRefEqual(CurrentThreadRef(), main_thread_ref_); -} - Thread::ScopedDisallowBlockingCalls::ScopedDisallowBlockingCalls() : thread_(Thread::Current()), previous_state_(thread_->SetAllowBlockingCalls(false)) {} diff --git a/rtc_base/thread.h b/rtc_base/thread.h index bc93e6533c..3c4ed558cd 100644 --- a/rtc_base/thread.h +++ b/rtc_base/thread.h @@ -141,8 +141,6 @@ class RTC_EXPORT ThreadManager { Thread* WrapCurrentThread(); void UnwrapCurrentThread(); - bool IsMainThread(); - #if RTC_DCHECK_IS_ON // Registers that a Send operation is to be performed between `source` and // `target`, while checking that this does not cause a send cycle that could @@ -188,9 +186,6 @@ class RTC_EXPORT ThreadManager { #if defined(WEBRTC_WIN) const DWORD key_; #endif - - // The thread to potentially autowrap. - const PlatformThreadRef main_thread_ref_; }; // WARNING! SUBCLASSES MUST CALL Stop() IN THEIR DESTRUCTORS! See ~Thread().