diff options
Diffstat (limited to 'base/threading')
-rw-r--r-- | base/threading/cross_process_platform_thread_delegate.h | 38 | ||||
-rw-r--r-- | base/threading/platform_thread.h | 36 | ||||
-rw-r--r-- | base/threading/platform_thread_apple.mm | 64 | ||||
-rw-r--r-- | base/threading/platform_thread_cros.cc | 38 | ||||
-rw-r--r-- | base/threading/platform_thread_fuchsia.cc | 10 | ||||
-rw-r--r-- | base/threading/platform_thread_linux.cc | 27 | ||||
-rw-r--r-- | base/threading/platform_thread_unittest.cc | 8 | ||||
-rw-r--r-- | base/threading/platform_thread_win.cc | 4 | ||||
-rw-r--r-- | base/threading/scoped_thread_priority_unittest.cc | 1 | ||||
-rw-r--r-- | base/threading/sequence_bound_unittest.cc | 5 | ||||
-rw-r--r-- | base/threading/thread.cc | 4 | ||||
-rw-r--r-- | base/threading/thread_checker.cc | 3 | ||||
-rw-r--r-- | base/threading/thread_checker.h | 5 | ||||
-rw-r--r-- | base/threading/thread_local_storage_perftest.cc | 1 | ||||
-rw-r--r-- | base/threading/thread_restrictions.h | 4 | ||||
-rw-r--r-- | base/threading/thread_unittest.cc | 6 |
16 files changed, 175 insertions, 79 deletions
diff --git a/base/threading/cross_process_platform_thread_delegate.h b/base/threading/cross_process_platform_thread_delegate.h new file mode 100644 index 000000000..8baa417ad --- /dev/null +++ b/base/threading/cross_process_platform_thread_delegate.h @@ -0,0 +1,38 @@ +// Copyright 2024 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_THREADING_CROSS_PROCESS_PLATFORM_THREAD_DELEGATE_H_ +#define BASE_THREADING_CROSS_PROCESS_PLATFORM_THREAD_DELEGATE_H_ + +#include "base/base_export.h" +#include "base/threading/platform_thread.h" + +namespace base { + +// A CrossProcessPlatformThreadDelegate can intercept thread type changes for +// threads including other processes. This can be used for ChromeOS so that the +// browser process can proxy thread type updates of child processes received +// from SandboxedProcessThreadTypeHandler to D-Bus because child processes don't +// have access to D-Bus. +class BASE_EXPORT CrossProcessPlatformThreadDelegate { + public: + CrossProcessPlatformThreadDelegate() = default; + + CrossProcessPlatformThreadDelegate( + const CrossProcessPlatformThreadDelegate&) = delete; + CrossProcessPlatformThreadDelegate& operator=( + const CrossProcessPlatformThreadDelegate&) = delete; + + virtual ~CrossProcessPlatformThreadDelegate() = default; + + // Invoked on thread type change. Returns true if the delegate handles + // adjusting thread properties. + virtual bool HandleThreadTypeChange(ProcessId process_id, + PlatformThreadId thread_id, + ThreadType thread_type) = 0; +}; + +} // namespace base + +#endif // BASE_THREADING_CROSS_PROCESS_PLATFORM_THREAD_DELEGATE_H_ diff --git a/base/threading/platform_thread.h b/base/threading/platform_thread.h index 0f8bcb0ca..c2ce87f53 100644 --- a/base/threading/platform_thread.h +++ b/base/threading/platform_thread.h @@ -286,11 +286,8 @@ class BASE_EXPORT PlatformThreadApple : public PlatformThreadBase { static TimeDelta GetCurrentThreadRealtimePeriodForTest(); - // Signals that the feature list has been initialized which allows to check - // the feature's value now and initialize state. This prevents race - // conditions where the feature is being checked while it is being - // initialized, which can cause a crash. - static void InitFeaturesPostFieldTrial(); + // Initializes features for this class. See `base::features::Init()`. + static void InitializeFeatures(); }; #endif // BUILDFLAG(IS_APPLE) @@ -321,6 +318,10 @@ class BASE_EXPORT PlatformThreadLinux : public PlatformThreadBase { ThreadType thread_type, IsViaIPC via_ipc); + // Toggles a specific thread's type at runtime. The thread must be of the + // current process. + static void SetThreadType(PlatformThreadId thread_id, ThreadType thread_type); + // For a given thread id and thread type, setup the cpuset and schedtune // CGroups for the thread. static void SetThreadCgroupsForThreadType(PlatformThreadId thread_id, @@ -329,17 +330,30 @@ class BASE_EXPORT PlatformThreadLinux : public PlatformThreadBase { // Determine if thread_id is a background thread by looking up whether // it is in the urgent or non-urgent cpuset static bool IsThreadBackgroundedForTest(PlatformThreadId thread_id); + + protected: + static void SetThreadTypeInternal(PlatformThreadId process_id, + PlatformThreadId thread_id, + ThreadType thread_type, + IsViaIPC via_ipc); }; #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) #if BUILDFLAG(IS_CHROMEOS) BASE_EXPORT BASE_DECLARE_FEATURE(kSetRtForDisplayThreads); +class CrossProcessPlatformThreadDelegate; + class BASE_EXPORT PlatformThreadChromeOS : public PlatformThreadLinux { public: - // Signals that the feature list has been initialized. Used for preventing - // race conditions and crashes, see comments in PlatformThreadApple. - static void InitFeaturesPostFieldTrial(); + // Sets a delegate which handles thread type changes for threads of another + // process. This must be externally synchronized with any call to + // SetCurrentThreadType. + static void SetCrossProcessPlatformThreadDelegate( + CrossProcessPlatformThreadDelegate* delegate); + + // Initializes features for this class. See `base::features::Init()`. + static void InitializeFeatures(); // Toggles a specific thread's type at runtime. This is the ChromeOS-specific // version and includes Linux's functionality but does slightly more. See @@ -370,6 +384,12 @@ class BASE_EXPORT PlatformThreadChromeOS : public PlatformThreadLinux { // Returns a SequenceChecker which should be used to verify that all // cross-process priority changes are performed without races. static SequenceCheckerImpl& GetCrossProcessThreadPrioritySequenceChecker(); + + protected: + static void SetThreadTypeInternal(PlatformThreadId process_id, + PlatformThreadId thread_id, + ThreadType thread_type, + IsViaIPC via_ipc); }; #endif // BUILDFLAG(IS_CHROMEOS) diff --git a/base/threading/platform_thread_apple.mm b/base/threading/platform_thread_apple.mm index 3f8db6bd3..c18ba13a1 100644 --- a/base/threading/platform_thread_apple.mm +++ b/base/threading/platform_thread_apple.mm @@ -30,7 +30,6 @@ namespace base { namespace { -NSString* const kThreadPriorityForTestKey = @"CrThreadPriorityForTestKey"; NSString* const kRealtimePeriodNsKey = @"CrRealtimePeriodNsKey"; } // namespace @@ -95,7 +94,7 @@ BASE_FEATURE(kOptimizedRealtimeThreadingMac, ); const Feature kUserInteractiveCompositingMac{"UserInteractiveCompositingMac", - FEATURE_DISABLED_BY_DEFAULT}; + FEATURE_ENABLED_BY_DEFAULT}; namespace { @@ -145,18 +144,12 @@ std::atomic<TimeConstraints> g_time_constraints; } // namespace // static -void PlatformThreadApple::InitFeaturesPostFieldTrial() { - // A DCHECK is triggered on FeatureList initialization if the state of a - // feature has been checked before. To avoid triggering this DCHECK in unit - // tests that call this before initializing the FeatureList, only check the - // state of the feature if the FeatureList is initialized. - if (FeatureList::GetInstance()) { - g_time_constraints.store(TimeConstraints::ReadFromFeatureParams()); - g_use_optimized_realtime_threading.store( - IsOptimizedRealtimeThreadingMacEnabled()); - g_user_interactive_compositing.store( - FeatureList::IsEnabled(kUserInteractiveCompositingMac)); - } +void PlatformThreadApple::InitializeFeatures() { + g_time_constraints.store(TimeConstraints::ReadFromFeatureParams()); + g_use_optimized_realtime_threading.store( + IsOptimizedRealtimeThreadingMacEnabled()); + g_user_interactive_compositing.store( + FeatureList::IsEnabled(kUserInteractiveCompositingMac)); } // static @@ -306,71 +299,68 @@ void SetCurrentThreadTypeImpl(ThreadType thread_type, // TODO(https://crbug.com/1280764): Remove this check. kCompositing is the // default on Mac, so this check is counter intuitive. if ([[NSThread currentThread] isMainThread] && - thread_type >= ThreadType::kCompositing) { + thread_type >= ThreadType::kCompositing && + !g_user_interactive_compositing.load(std::memory_order_relaxed)) { DCHECK(thread_type == ThreadType::kDefault || thread_type == ThreadType::kCompositing); return; } - ThreadPriorityForTest priority = ThreadPriorityForTest::kNormal; switch (thread_type) { case ThreadType::kBackground: - priority = ThreadPriorityForTest::kBackground; pthread_set_qos_class_self_np(QOS_CLASS_BACKGROUND, 0); break; case ThreadType::kUtility: - priority = ThreadPriorityForTest::kUtility; pthread_set_qos_class_self_np(QOS_CLASS_UTILITY, 0); break; case ThreadType::kResourceEfficient: - priority = ThreadPriorityForTest::kUtility; pthread_set_qos_class_self_np(QOS_CLASS_UTILITY, 0); break; case ThreadType::kDefault: - priority = ThreadPriorityForTest::kNormal; pthread_set_qos_class_self_np(QOS_CLASS_USER_INITIATED, 0); break; case ThreadType::kCompositing: if (g_user_interactive_compositing.load(std::memory_order_relaxed)) { - priority = ThreadPriorityForTest::kDisplay; pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0); } else { - priority = ThreadPriorityForTest::kNormal; pthread_set_qos_class_self_np(QOS_CLASS_USER_INITIATED, 0); } break; case ThreadType::kDisplayCritical: { - priority = ThreadPriorityForTest::kDisplay; pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0); break; } case ThreadType::kRealtimeAudio: - priority = ThreadPriorityForTest::kRealtimeAudio; SetPriorityRealtimeAudio(GetCurrentThreadRealtimePeriod()); DCHECK_EQ([NSThread.currentThread threadPriority], 1.0); break; } - - NSThread.currentThread.threadDictionary[kThreadPriorityForTestKey] = - @(static_cast<int>(priority)); } } // namespace internal // static ThreadPriorityForTest PlatformThreadBase::GetCurrentThreadPriorityForTest() { - NSNumber* priority = base::apple::ObjCCast<NSNumber>( - NSThread.currentThread.threadDictionary[kThreadPriorityForTestKey]); - - if (!priority) { - return ThreadPriorityForTest::kNormal; + if ([NSThread.currentThread threadPriority] == 1.0) { + // Set to 1 for a non-fixed thread.) + return ThreadPriorityForTest::kRealtimeAudio; } - ThreadPriorityForTest thread_priority = - static_cast<ThreadPriorityForTest>(priority.intValue); - DCHECK_GE(thread_priority, ThreadPriorityForTest::kBackground); - DCHECK_LE(thread_priority, ThreadPriorityForTest::kMaxValue); - return thread_priority; + qos_class_t qos_class; + int relative_priority; + pthread_get_qos_class_np(pthread_self(), &qos_class, &relative_priority); + switch (qos_class) { + case QOS_CLASS_BACKGROUND: + return ThreadPriorityForTest::kBackground; + case QOS_CLASS_UTILITY: + return ThreadPriorityForTest::kUtility; + case QOS_CLASS_USER_INITIATED: + return ThreadPriorityForTest::kNormal; + case QOS_CLASS_USER_INTERACTIVE: + return ThreadPriorityForTest::kDisplay; + default: + return ThreadPriorityForTest::kNormal; + } } size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { diff --git a/base/threading/platform_thread_cros.cc b/base/threading/platform_thread_cros.cc index c01b7b413..f89442bd2 100644 --- a/base/threading/platform_thread_cros.cc +++ b/base/threading/platform_thread_cros.cc @@ -4,18 +4,18 @@ // Description: ChromeOS specific Linux code layered on top of // base/threading/platform_thread_linux{,_base}.cc. -#include "base/feature_list.h" -#include "base/no_destructor.h" -#include "base/threading/platform_thread.h" -#include "base/threading/platform_thread_internal_posix.h" - #include "base/base_switches.h" #include "base/command_line.h" +#include "base/feature_list.h" #include "base/files/file_util.h" #include "base/metrics/field_trial_params.h" +#include "base/no_destructor.h" #include "base/process/internal_linux.h" #include "base/process/process.h" #include "base/strings/stringprintf.h" +#include "base/threading/cross_process_platform_thread_delegate.h" +#include "base/threading/platform_thread.h" +#include "base/threading/platform_thread_internal_posix.h" #include <sys/resource.h> @@ -34,6 +34,9 @@ BASE_FEATURE(kSetRtForDisplayThreads, FEATURE_DISABLED_BY_DEFAULT); namespace { +CrossProcessPlatformThreadDelegate* g_cross_process_platform_thread_delegate = + nullptr; + std::atomic<bool> g_use_sched_util(true); std::atomic<bool> g_scheduler_hints_adjusted(false); std::atomic<bool> g_threads_bg_enabled(false); @@ -303,7 +306,7 @@ void SetThreadNiceFromType(ProcessId process_id, } } -void PlatformThreadChromeOS::InitFeaturesPostFieldTrial() { +void PlatformThreadChromeOS::InitializeFeatures() { DCHECK(FeatureList::GetInstance()); g_threads_bg_enabled.store(FeatureList::IsEnabled(kSetThreadBgForBgProcess)); g_display_threads_rt.store(FeatureList::IsEnabled(kSetRtForDisplayThreads)); @@ -340,6 +343,16 @@ void PlatformThreadChromeOS::InitFeaturesPostFieldTrial() { } // static +void PlatformThreadChromeOS::SetCrossProcessPlatformThreadDelegate( + CrossProcessPlatformThreadDelegate* delegate) { + // A component cannot override a delegate set by another component, thus + // disallow setting a delegate when one already exists. + DCHECK_NE(!!g_cross_process_platform_thread_delegate, !!delegate); + + g_cross_process_platform_thread_delegate = delegate; +} + +// static bool PlatformThreadChromeOS::IsThreadsBgFeatureEnabled() { return g_threads_bg_enabled.load(); } @@ -366,6 +379,19 @@ void PlatformThreadChromeOS::SetThreadType(ProcessId process_id, PlatformThreadId thread_id, ThreadType thread_type, IsViaIPC via_ipc) { + if (g_cross_process_platform_thread_delegate && + g_cross_process_platform_thread_delegate->HandleThreadTypeChange( + process_id, thread_id, thread_type)) { + return; + } + SetThreadTypeInternal(process_id, thread_id, thread_type, via_ipc); +} + +// static +void PlatformThreadChromeOS::SetThreadTypeInternal(ProcessId process_id, + PlatformThreadId thread_id, + ThreadType thread_type, + IsViaIPC via_ipc) { // TODO(b/262267726): Re-use common code with PlatformThreadLinux::SetThreadType // Should not be called concurrently with other functions // like SetThreadBackgrounded. diff --git a/base/threading/platform_thread_fuchsia.cc b/base/threading/platform_thread_fuchsia.cc index 6c66178b2..341344659 100644 --- a/base/threading/platform_thread_fuchsia.cc +++ b/base/threading/platform_thread_fuchsia.cc @@ -4,15 +4,15 @@ #include "base/threading/platform_thread.h" +#include <fidl/fuchsia.media/cpp/fidl.h> +#include <lib/fdio/directory.h> +#include <lib/sys/cpp/component_context.h> #include <pthread.h> #include <sched.h> #include <zircon/syscalls.h> #include <mutex> - -#include <fidl/fuchsia.media/cpp/fidl.h> -#include <lib/fdio/directory.h> -#include <lib/sys/cpp/component_context.h> +#include <string_view> #include "base/fuchsia/fuchsia_component_connect.h" #include "base/fuchsia/fuchsia_logging.h" @@ -41,7 +41,7 @@ fidl::SyncClient<fuchsia_media::ProfileProvider> ConnectProfileProvider() { // that period. // TODO(crbug.com/1365682): Migrate to the new fuchsia.scheduler.ProfileProvider // API when available. -void SetThreadRole(StringPiece role_name, +void SetThreadRole(std::string_view role_name, TimeDelta period = {}, float capacity = 0.0f) { DCHECK_GE(capacity, 0.0); diff --git a/base/threading/platform_thread_linux.cc b/base/threading/platform_thread_linux.cc index 53e5983fb..ef9a0db13 100644 --- a/base/threading/platform_thread_linux.cc +++ b/base/threading/platform_thread_linux.cc @@ -153,14 +153,7 @@ bool CanSetThreadTypeToRealtimeAudio() { bool SetCurrentThreadTypeForPlatform(ThreadType thread_type, MessagePumpType pump_type_hint) { - const PlatformThreadId tid = PlatformThread::CurrentId(); - - if (g_thread_type_delegate && - g_thread_type_delegate->HandleThreadTypeChange(tid, thread_type)) { - return true; - } - - PlatformThread::SetThreadType(getpid(), tid, thread_type, IsViaIPC(false)); + PlatformThreadLinux::SetThreadType(PlatformThread::CurrentId(), thread_type); return true; } @@ -276,6 +269,24 @@ void PlatformThreadLinux::SetThreadType(ProcessId process_id, PlatformThreadId thread_id, ThreadType thread_type, IsViaIPC via_ipc) { + SetThreadTypeInternal(process_id, thread_id, thread_type, via_ipc); +} + +// static +void PlatformThreadLinux::SetThreadType(PlatformThreadId thread_id, + ThreadType thread_type) { + if (g_thread_type_delegate && + g_thread_type_delegate->HandleThreadTypeChange(thread_id, thread_type)) { + return; + } + SetThreadTypeInternal(getpid(), thread_id, thread_type, IsViaIPC(false)); +} + +// static +void PlatformThreadLinux::SetThreadTypeInternal(ProcessId process_id, + PlatformThreadId thread_id, + ThreadType thread_type, + IsViaIPC via_ipc) { SetThreadCgroupsForThreadType(thread_id, thread_type); // Some scheduler syscalls require thread ID of 0 for current thread. diff --git a/base/threading/platform_thread_unittest.cc b/base/threading/platform_thread_unittest.cc index 13fe7b71a..ec57b267b 100644 --- a/base/threading/platform_thread_unittest.cc +++ b/base/threading/platform_thread_unittest.cc @@ -20,6 +20,7 @@ #include "base/threading/platform_thread_internal_posix.h" #elif BUILDFLAG(IS_WIN) #include <windows.h> + #include "base/threading/platform_thread_win.h" #endif @@ -509,7 +510,8 @@ TEST(PlatformThreadTest, SetCurrentThreadTypeTest) { TestPriorityResultingFromThreadType(ThreadType::kDefault, ThreadPriorityForTest::kNormal); -#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS) +#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS) || \ + BUILDFLAG(IS_APPLE) TestPriorityResultingFromThreadType(ThreadType::kCompositing, ThreadPriorityForTest::kDisplay); TestPriorityResultingFromThreadType(ThreadType::kCompositing, @@ -518,7 +520,7 @@ TEST(PlatformThreadTest, SetCurrentThreadTypeTest) { TestPriorityResultingFromThreadType(ThreadType::kCompositing, MessagePumpType::IO, ThreadPriorityForTest::kDisplay); -#else // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FUCHSIA) +#else // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_FUCHSIA) TestPriorityResultingFromThreadType(ThreadType::kCompositing, ThreadPriorityForTest::kNormal); TestPriorityResultingFromThreadType(ThreadType::kCompositing, @@ -672,7 +674,7 @@ TEST_P(RealtimePlatformThreadTest, RealtimeAudioConfigMac) { feature_list.InitAndDisableFeature(kOptimizedRealtimeThreadingMac); } - PlatformThread::InitFeaturesPostFieldTrial(); + PlatformThread::InitializeFeatures(); VerifyRealtimeConfig(std::get<2>(GetParam())); } diff --git a/base/threading/platform_thread_win.cc b/base/threading/platform_thread_win.cc index c4e558629..bbf14b89c 100644 --- a/base/threading/platform_thread_win.cc +++ b/base/threading/platform_thread_win.cc @@ -4,6 +4,8 @@ #include "base/threading/platform_thread_win.h" +#include <windows.h> + #include <stddef.h> #include <string> @@ -29,8 +31,6 @@ #include "build/build_config.h" #include "partition_alloc/partition_alloc_buildflags.h" -#include <windows.h> - #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) #include "partition_alloc/stack/stack.h" #endif diff --git a/base/threading/scoped_thread_priority_unittest.cc b/base/threading/scoped_thread_priority_unittest.cc index b44c1a326..72a56b3dd 100644 --- a/base/threading/scoped_thread_priority_unittest.cc +++ b/base/threading/scoped_thread_priority_unittest.cc @@ -35,6 +35,7 @@ class ScopedThreadPriorityTest : public testing::Test { protected: void SetUp() override { // Ensures the default thread priority is set. + PlatformThread::SetCurrentThreadType(ThreadType::kDefault); ASSERT_EQ(ThreadPriorityForTest::kNormal, PlatformThread::GetCurrentThreadPriorityForTest()); } diff --git a/base/threading/sequence_bound_unittest.cc b/base/threading/sequence_bound_unittest.cc index 5d9a7188f..6b4d360bf 100644 --- a/base/threading/sequence_bound_unittest.cc +++ b/base/threading/sequence_bound_unittest.cc @@ -6,6 +6,7 @@ #include <functional> #include <memory> +#include <string_view> #include <utility> #include "base/memory/raw_ptr.h" @@ -30,7 +31,7 @@ class EventLogger { public: EventLogger() = default; - void AddEvent(StringPiece event) { + void AddEvent(std::string_view event) { AutoLock guard(lock_); events_.push_back(std::string(event)); } @@ -249,7 +250,7 @@ class BoxedValue { } private: - void AddEventIfNeeded(StringPiece event) const { + void AddEventIfNeeded(std::string_view event) const { if (logger_) { logger_->AddEvent(event); } diff --git a/base/threading/thread.cc b/base/threading/thread.cc index 8f87f3f18..3398fa803 100644 --- a/base/threading/thread.cc +++ b/base/threading/thread.cc @@ -22,12 +22,12 @@ #include "base/task/sequence_manager/sequence_manager_impl.h" #include "base/task/sequence_manager/task_queue.h" #include "base/task/single_thread_task_runner.h" -#include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/threading/thread_id_name_manager.h" #include "base/threading/thread_restrictions.h" #include "base/types/pass_key.h" #include "build/build_config.h" #include "third_party/abseil-cpp/absl/base/attributes.h" +#include "third_party/abseil-cpp/absl/base/dynamic_annotations.h" #if (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL)) || BUILDFLAG(IS_FUCHSIA) #include <optional> @@ -368,7 +368,7 @@ void Thread::ThreadMain() { // Complete the initialization of our Thread object. PlatformThread::SetName(name_.c_str()); - ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. + ABSL_ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector. // Lazily initialize the |message_loop| so that it can run on this thread. DCHECK(delegate_); diff --git a/base/threading/thread_checker.cc b/base/threading/thread_checker.cc index 4baec82b4..eb3bd1fbe 100644 --- a/base/threading/thread_checker.cc +++ b/base/threading/thread_checker.cc @@ -7,6 +7,7 @@ #if DCHECK_IS_ON() #include <memory> #include <ostream> +#include <string_view> #include "base/check.h" #include "base/debug/stack_trace.h" @@ -25,7 +26,7 @@ ScopedValidateThreadChecker::ScopedValidateThreadChecker( ScopedValidateThreadChecker::ScopedValidateThreadChecker( const ThreadChecker& checker, - const StringPiece& msg) { + std::string_view msg) { std::unique_ptr<debug::StackTrace> bound_at; DCHECK(checker.CalledOnValidThread(&bound_at)) << msg diff --git a/base/threading/thread_checker.h b/base/threading/thread_checker.h index e809f04da..650d6b65d 100644 --- a/base/threading/thread_checker.h +++ b/base/threading/thread_checker.h @@ -5,10 +5,11 @@ #ifndef BASE_THREADING_THREAD_CHECKER_H_ #define BASE_THREADING_THREAD_CHECKER_H_ +#include <string_view> + #include "base/base_export.h" #include "base/dcheck_is_on.h" #include "base/macros/uniquify.h" -#include "base/strings/string_piece.h" #include "base/thread_annotations.h" #include "base/threading/thread_checker_impl.h" @@ -136,7 +137,7 @@ class BASE_EXPORT SCOPED_LOCKABLE ScopedValidateThreadChecker { explicit ScopedValidateThreadChecker(const ThreadChecker& checker) EXCLUSIVE_LOCK_FUNCTION(checker); ScopedValidateThreadChecker(const ThreadChecker& checker, - const StringPiece& msg) + std::string_view msg) EXCLUSIVE_LOCK_FUNCTION(checker); ScopedValidateThreadChecker(const ScopedValidateThreadChecker&) = delete; diff --git a/base/threading/thread_local_storage_perftest.cc b/base/threading/thread_local_storage_perftest.cc index 9f5d1c0dc..ebf2e6bb0 100644 --- a/base/threading/thread_local_storage_perftest.cc +++ b/base/threading/thread_local_storage_perftest.cc @@ -22,6 +22,7 @@ #if BUILDFLAG(IS_WIN) #include <windows.h> + #include "base/win/windows_types.h" #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) #include <pthread.h> diff --git a/base/threading/thread_restrictions.h b/base/threading/thread_restrictions.h index e9b836636..998eb457e 100644 --- a/base/threading/thread_restrictions.h +++ b/base/threading/thread_restrictions.h @@ -176,6 +176,7 @@ class MojoUtils; } namespace system { class StatisticsProviderImpl; +class ProcStatFile; } // namespace system } // namespace ash namespace audio { @@ -361,6 +362,7 @@ class ProxyConfigServiceWin; class ScopedAllowBlockingForSettingGetter; namespace internal { class AddressTrackerLinux; +class PemFileCertStore; } } // namespace net namespace printing { @@ -587,6 +589,7 @@ class BASE_EXPORT [[maybe_unused, nodiscard]] ScopedAllowBlocking { friend class ash::StartupCustomizationDocument; // http://crosbug.com/11103 friend class ash::StartupUtils; friend class ash::converters::diagnostics::MojoUtils; // http://b/322741627 + friend class ash::system::ProcStatFile; friend class base::AdjustOOMScoreHelper; friend class base::ChromeOSVersionInfo; friend class base::Process; @@ -631,6 +634,7 @@ class BASE_EXPORT [[maybe_unused, nodiscard]] ScopedAllowBlocking { friend class net::ProxyConfigServiceWin; // http://crbug.com/61453 friend class net:: ScopedAllowBlockingForSettingGetter; // http://crbug.com/69057 + friend class net::internal::PemFileCertStore; friend class printing::LocalPrinterHandlerDefault; friend class printing::PrintBackendServiceManager; friend class printing::PrintPreviewUIUntrusted; diff --git a/base/threading/thread_unittest.cc b/base/threading/thread_unittest.cc index e91b4fe0e..2f1c81a6d 100644 --- a/base/threading/thread_unittest.cc +++ b/base/threading/thread_unittest.cc @@ -23,13 +23,13 @@ #include "base/task/single_thread_task_runner.h" #include "base/test/bind.h" #include "base/test/gtest_util.h" -#include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/threading/platform_thread.h" #include "base/time/time.h" #include "build/build_config.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +#include "third_party/abseil-cpp/absl/base/dynamic_annotations.h" #if DCHECK_IS_ON() #include "base/threading/thread_restrictions.h" @@ -43,7 +43,7 @@ namespace base { namespace { void ToggleValue(bool* value) { - ANNOTATE_BENIGN_RACE( + ABSL_ANNOTATE_BENIGN_RACE( value, "Test-only data race on boolean in base/thread_unittest"); *value = !*value; } @@ -52,7 +52,7 @@ class SleepInsideInitThread : public Thread { public: SleepInsideInitThread() : Thread("none") { init_called_ = false; - ANNOTATE_BENIGN_RACE( + ABSL_ANNOTATE_BENIGN_RACE( this, "Benign test-only data race on vptr - http://crbug.com/98219"); } |