diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/base/threading | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/threading')
-rw-r--r-- | chromium/base/threading/hang_watcher.cc | 39 | ||||
-rw-r--r-- | chromium/base/threading/hang_watcher.h | 6 | ||||
-rw-r--r-- | chromium/base/threading/hang_watcher_unittest.cc | 34 | ||||
-rw-r--r-- | chromium/base/threading/platform_thread_win.cc | 8 | ||||
-rw-r--r-- | chromium/base/threading/scoped_blocking_call.cc | 2 | ||||
-rw-r--r-- | chromium/base/threading/scoped_thread_priority.cc | 2 | ||||
-rw-r--r-- | chromium/base/threading/sequence_bound.h | 24 | ||||
-rw-r--r-- | chromium/base/threading/sequence_bound_unittest.cc | 23 | ||||
-rw-r--r-- | chromium/base/threading/sequenced_task_runner_handle_unittest.cc | 2 | ||||
-rw-r--r-- | chromium/base/threading/thread.cc | 8 | ||||
-rw-r--r-- | chromium/base/threading/thread_checker.h | 4 | ||||
-rw-r--r-- | chromium/base/threading/thread_checker_unittest.cc | 1 | ||||
-rw-r--r-- | chromium/base/threading/thread_local.h | 2 | ||||
-rw-r--r-- | chromium/base/threading/thread_restrictions.cc | 2 | ||||
-rw-r--r-- | chromium/base/threading/thread_restrictions.h | 8 | ||||
-rw-r--r-- | chromium/base/threading/thread_unittest.cc | 1 |
16 files changed, 71 insertions, 95 deletions
diff --git a/chromium/base/threading/hang_watcher.cc b/chromium/base/threading/hang_watcher.cc index 9a4cddea653..ccd1ea215c8 100644 --- a/chromium/base/threading/hang_watcher.cc +++ b/chromium/base/threading/hang_watcher.cc @@ -118,7 +118,6 @@ HangWatcher::HangWatcher() DCHECK(!g_instance); g_instance = this; - Start(); } HangWatcher::~HangWatcher() { @@ -147,22 +146,21 @@ void HangWatcher::Wait() { while (true) { // Amount by which the actual time spent sleeping can deviate from // the target time and still be considered timely. - constexpr base::TimeDelta wait_drift_tolerance = + constexpr base::TimeDelta kWaitDriftTolerance = base::TimeDelta::FromMilliseconds(100); - base::TimeTicks time_before_wait = tick_clock_->NowTicks(); + const base::TimeTicks time_before_wait = tick_clock_->NowTicks(); // Sleep until next scheduled monitoring or until signaled. - bool was_signaled = should_monitor_.TimedWait(monitor_period_); + const bool was_signaled = should_monitor_.TimedWait(monitor_period_); - if (after_wait_callback_) { + if (after_wait_callback_) after_wait_callback_.Run(time_before_wait); - } - base::TimeTicks time_after_wait = tick_clock_->NowTicks(); - base::TimeDelta wait_time = time_after_wait - time_before_wait; - bool wait_was_normal = - wait_time <= (monitor_period_ + wait_drift_tolerance); + const base::TimeTicks time_after_wait = tick_clock_->NowTicks(); + const base::TimeDelta wait_time = time_after_wait - time_before_wait; + const bool wait_was_normal = + wait_time <= (monitor_period_ + kWaitDriftTolerance); if (!wait_was_normal) { // If the time spent waiting was too high it might indicate the machine is @@ -190,9 +188,8 @@ void HangWatcher::Wait() { } // Stop waiting. - if (wait_was_normal || was_signaled) { + if (wait_was_normal || was_signaled) return; - } } } @@ -202,20 +199,15 @@ void HangWatcher::Run() { DCHECK_CALLED_ON_VALID_THREAD(hang_watcher_thread_checker_); while (keep_monitoring_.load(std::memory_order_relaxed)) { - // If there is nothing to watch sleep until there is. - if (IsWatchListEmpty()) { - should_monitor_.Wait(); - } else { - Monitor(); + Wait(); + if (!IsWatchListEmpty() && + keep_monitoring_.load(std::memory_order_relaxed)) { + Monitor(); if (after_monitor_closure_for_testing_) { after_monitor_closure_for_testing_.Run(); } } - - if (keep_monitoring_.load(std::memory_order_relaxed)) { - Wait(); - } } } @@ -238,11 +230,6 @@ ScopedClosureRunner HangWatcher::RegisterThread() { watch_states_.push_back( internal::HangWatchState::CreateHangWatchStateForCurrentThread()); - // Now that there is a thread to monitor we wake the HangWatcher thread. - if (watch_states_.size() == 1) { - should_monitor_.Signal(); - } - return ScopedClosureRunner(BindOnce(&HangWatcher::UnregisterThread, Unretained(HangWatcher::GetInstance()))); } diff --git a/chromium/base/threading/hang_watcher.h b/chromium/base/threading/hang_watcher.h index dd496c79f7d..7d848da4475 100644 --- a/chromium/base/threading/hang_watcher.h +++ b/chromium/base/threading/hang_watcher.h @@ -150,6 +150,9 @@ class BASE_EXPORT HangWatcher : public DelegateSimpleThread::Delegate { // non-actionable stack trace in the crash recorded. void BlockIfCaptureInProgress(); + // Begin executing the monitoring loop on the HangWatcher thread. + void Start(); + private: // Use to assert that functions are called on the monitoring thread. THREAD_CHECKER(hang_watcher_thread_checker_); @@ -211,9 +214,6 @@ class BASE_EXPORT HangWatcher : public DelegateSimpleThread::Delegate { void CaptureHang(base::TimeTicks capture_time) EXCLUSIVE_LOCKS_REQUIRED(watch_state_lock_) LOCKS_EXCLUDED(capture_lock_); - // Call Run() on the HangWatcher thread. - void Start(); - // Stop all monitoring and join the HangWatcher thread. void Stop(); diff --git a/chromium/base/threading/hang_watcher_unittest.cc b/chromium/base/threading/hang_watcher_unittest.cc index 4a6033fe235..0849b98ec2c 100644 --- a/chromium/base/threading/hang_watcher_unittest.cc +++ b/chromium/base/threading/hang_watcher_unittest.cc @@ -95,6 +95,9 @@ class HangWatcherTest : public testing::Test { // We're not testing the monitoring loop behavior in this test so we want to // trigger monitoring manually. hang_watcher_.SetMonitoringPeriodForTesting(base::TimeDelta::Max()); + + // Start the monitoring loop. + hang_watcher_.Start(); } HangWatcherTest(const HangWatcherTest& other) = delete; @@ -169,19 +172,6 @@ class HangWatcherBlockingThreadTest : public HangWatcherTest { }; } // namespace -TEST_F(HangWatcherTest, NoRegisteredThreads) { - ASSERT_FALSE(monitor_event_.IsSignaled()); - - // Signal to advance the Run() loop. - base::HangWatcher::GetInstance()->SignalMonitorEventForTesting(); - - // Monitoring should just not happen when there are no registered threads. - // Wait a while to make sure it does not. - ASSERT_FALSE(monitor_event_.TimedWait(base::TimeDelta::FromSeconds(1))); - - ASSERT_FALSE(hang_event_.IsSignaled()); -} - TEST_F(HangWatcherTest, NestedScopes) { // Create a state object for the test thread since this test is single // threaded. @@ -307,7 +297,7 @@ class HangWatcherSnapshotTest : public testing::Test { } // namespace // TODO(crbug.com/2193655): Test flaky on iPad. -TEST_F(HangWatcherSnapshotTest, DISABLED_HungThreadIDs) { +TEST_F(HangWatcherSnapshotTest, HungThreadIDs) { // During hang capture the list of hung threads should be populated. hang_watcher_.SetOnHangClosureForTesting(base::BindLambdaForTesting([this]() { EXPECT_EQ(hang_watcher_.GrabWatchStateSnapshotForTesting() @@ -325,6 +315,8 @@ TEST_F(HangWatcherSnapshotTest, DISABLED_HungThreadIDs) { monitor_event_.Signal(); })); + hang_watcher_.Start(); + // Register the main test thread for hang watching. auto unregister_thread_closure_ = hang_watcher_.RegisterThread(); @@ -437,6 +429,8 @@ TEST_F(HangWatcherPeriodicMonitoringTest, // wrong reasons. InstallAfterWaitCallback(kMonitoringPeriod); + hang_watcher_.Start(); + // Unblock the test thread. No thread ever registered after the HangWatcher // was created in the test's constructor. No monitoring should have taken // place. @@ -475,7 +469,9 @@ TEST_F(HangWatcherPeriodicMonitoringTest, PeriodicCallsTakePlace) { // Monitor(). This would inhibit monitoring. InstallAfterWaitCallback(kMonitoringPeriod); - // Register a thread, kicks off monitoring. + hang_watcher_.Start(); + + // Register a thread, unregister_thread_closure_ = hang_watcher_.RegisterThread(); run_loop.Run(); @@ -487,7 +483,7 @@ TEST_F(HangWatcherPeriodicMonitoringTest, PeriodicCallsTakePlace) { // If the HangWatcher detects it slept for longer than expected it will not // monitor. // TODO(crbug.com/1081654): Test flaky on ChromeOS. -TEST_F(HangWatcherPeriodicMonitoringTest, DISABLED_NoMonitorOnOverSleep) { +TEST_F(HangWatcherPeriodicMonitoringTest, NoMonitorOnOverSleep) { RunLoop run_loop; // If a call to HangWatcher::Monitor() takes place the test will instantly @@ -502,7 +498,9 @@ TEST_F(HangWatcherPeriodicMonitoringTest, DISABLED_NoMonitorOnOverSleep) { // detect oversleeping every time. This will keep it from monitoring. InstallAfterWaitCallback(base::TimeDelta::FromMinutes(1)); - // Register a thread, kicks off monitoring. + hang_watcher_.Start(); + + // Register a thread. unregister_thread_closure_ = hang_watcher_.RegisterThread(); // Unblock the test thread. All waits were perceived as oversleeping so all @@ -538,6 +536,8 @@ class HangWatchScopeBlockingTest : public testing::Test { // Make sure no periodic monitoring takes place. hang_watcher_.SetMonitoringPeriodForTesting(base::TimeDelta::Max()); + hang_watcher_.Start(); + // Register the test main thread for hang watching. unregister_thread_closure_ = hang_watcher_.RegisterThread(); } diff --git a/chromium/base/threading/platform_thread_win.cc b/chromium/base/threading/platform_thread_win.cc index 9b624757165..c87b5c08d90 100644 --- a/chromium/base/threading/platform_thread_win.cc +++ b/chromium/base/threading/platform_thread_win.cc @@ -16,6 +16,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/scoped_blocking_call.h" +#include "base/threading/scoped_thread_priority.h" #include "base/threading/thread_id_name_manager.h" #include "base/threading/thread_restrictions.h" #include "base/time/time_override.h" @@ -115,6 +116,13 @@ DWORD __stdcall ThreadFunc(void* params) { PlatformThread::CurrentId()); } + // Ensure thread priority is at least NORMAL before initiating thread + // destruction. Thread destruction on Windows holds the LdrLock while + // performing TLS destruction which causes hangs if performed at background + // priority (priority inversion) (see: http://crbug.com/1096203). + if (PlatformThread::GetCurrentThreadPriority() < ThreadPriority::NORMAL) + PlatformThread::SetCurrentThreadPriority(ThreadPriority::NORMAL); + return 0; } diff --git a/chromium/base/threading/scoped_blocking_call.cc b/chromium/base/threading/scoped_blocking_call.cc index 62edcd2af48..e8b2900874b 100644 --- a/chromium/base/threading/scoped_blocking_call.cc +++ b/chromium/base/threading/scoped_blocking_call.cc @@ -8,7 +8,7 @@ #include "base/threading/thread_local.h" #include "base/threading/thread_restrictions.h" #include "base/time/time.h" -#include "base/trace_event/trace_event.h" +#include "base/trace_event/base_tracing.h" #include "build/build_config.h" namespace base { diff --git a/chromium/base/threading/scoped_thread_priority.cc b/chromium/base/threading/scoped_thread_priority.cc index 396071906f2..e33c76f525f 100644 --- a/chromium/base/threading/scoped_thread_priority.cc +++ b/chromium/base/threading/scoped_thread_priority.cc @@ -6,7 +6,7 @@ #include "base/location.h" #include "base/threading/platform_thread.h" -#include "base/trace_event/trace_event.h" +#include "base/trace_event/base_tracing.h" namespace base { namespace internal { diff --git a/chromium/base/threading/sequence_bound.h b/chromium/base/threading/sequence_bound.h index b235fe221c3..3ee8ef6e4c9 100644 --- a/chromium/base/threading/sequence_bound.h +++ b/chromium/base/threading/sequence_bound.h @@ -94,26 +94,6 @@ namespace base { // SequenceBound<MyDerivedClass>(main_task_runner, ctor args); // auto c = new SomeConsumer(std::move(widget)); // upcasts to MyClass -namespace internal { - -// If we can't cast |Base*| into |Derived*|, then it's a virtual base if and -// only if |Base| is actually a base class of |Derived|. Otherwise (including -// unrelated types), it isn't. We default to Derived* so that the -// specialization below will apply when the cast to |Derived*| is valid. -template <typename Base, typename Derived, typename = Derived*> -struct is_virtual_base_of : public std::is_base_of<Base, Derived> {}; - -// If we can cast |Base*| into |Derived*|, then it's definitely not a virtual -// base. When this happens, we'll match the default third template argument. -template <typename Base, typename Derived> -struct is_virtual_base_of<Base, - Derived, - decltype(static_cast<Derived*>( - static_cast<Base*>(nullptr)))> : std::false_type { -}; - -} // namespace internal - template <typename T> class SequenceBound { public: @@ -134,7 +114,9 @@ class SequenceBound { Args&&... args) : impl_task_runner_(std::move(task_runner)) { // Allocate space for but do not construct an instance of |T|. - storage_ = AlignedAlloc(sizeof(T), alignof(T)); + // AlignedAlloc() requires alignment be a multiple of sizeof(void*). + storage_ = AlignedAlloc( + sizeof(T), sizeof(void*) > alignof(T) ? sizeof(void*) : alignof(T)); t_ = reinterpret_cast<T*>(storage_); // Post construction to the impl thread. diff --git a/chromium/base/threading/sequence_bound_unittest.cc b/chromium/base/threading/sequence_bound_unittest.cc index dfaae6c832b..ecf0e3543e8 100644 --- a/chromium/base/threading/sequence_bound_unittest.cc +++ b/chromium/base/threading/sequence_bound_unittest.cc @@ -333,23 +333,6 @@ TEST_F(SequenceBoundTest, ResetOnNullObjectWorks) { derived.Reset(); } -TEST_F(SequenceBoundTest, IsVirtualBaseClassOf) { - // Check that is_virtual_base_of<> works properly. - - // Neither |Base| nor |Derived| is a virtual base of the other. - static_assert(!internal::is_virtual_base_of<Base, Derived>::value, - "|Base| shouldn't be a virtual base of |Derived|"); - static_assert(!internal::is_virtual_base_of<Derived, Base>::value, - "|Derived| shouldn't be a virtual base of |Base|"); - - // |Base| should be a virtual base class of |VirtuallyDerived|, but not the - // other way. - static_assert(internal::is_virtual_base_of<Base, VirtuallyDerived>::value, - "|Base| should be a virtual base of |VirtuallyDerived|"); - static_assert(!internal::is_virtual_base_of<VirtuallyDerived, Base>::value, - "|VirtuallyDerived shouldn't be a virtual base of |Base|"); -} - TEST_F(SequenceBoundTest, LvalueConstructionParameter) { // Note here that |value_ptr| is an lvalue, while |&value| would be an rvalue. Value value = kInitialValue; @@ -408,4 +391,10 @@ TEST_F(SequenceBoundTest, ResetWithCallbackAfterDestruction) { loop.Run(); } +TEST_F(SequenceBoundTest, SmallObject) { + class EmptyClass {}; + SequenceBound<EmptyClass> value(task_runner_); + // Test passes if SequenceBound constructor does not crash in AlignedAlloc(). +} + } // namespace base diff --git a/chromium/base/threading/sequenced_task_runner_handle_unittest.cc b/chromium/base/threading/sequenced_task_runner_handle_unittest.cc index fa7dec1c734..8f4933e1114 100644 --- a/chromium/base/threading/sequenced_task_runner_handle_unittest.cc +++ b/chromium/base/threading/sequenced_task_runner_handle_unittest.cc @@ -67,7 +67,7 @@ TEST_F(SequencedTaskRunnerHandleTest, FromThreadPoolSequencedTask) { } TEST_F(SequencedTaskRunnerHandleTest, NoHandleFromUnsequencedTask) { - base::PostTask(base::BindOnce( + base::ThreadPool::PostTask(base::BindOnce( []() { EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet()); })); task_environment_.RunUntilIdle(); } diff --git a/chromium/base/threading/thread.cc b/chromium/base/threading/thread.cc index d264c1d2602..8659724616a 100644 --- a/chromium/base/threading/thread.cc +++ b/chromium/base/threading/thread.cc @@ -278,9 +278,11 @@ void Thread::DetachFromSequence() { } PlatformThreadId Thread::GetThreadId() const { - // If the thread is created but not started yet, wait for |id_| being ready. - base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_wait; - id_event_.Wait(); + if (!id_event_.IsSignaled()) { + // If the thread is created but not started yet, wait for |id_| being ready. + base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_wait; + id_event_.Wait(); + } return id_; } diff --git a/chromium/base/threading/thread_checker.h b/chromium/base/threading/thread_checker.h index e1495344f22..48646623ab8 100644 --- a/chromium/base/threading/thread_checker.h +++ b/chromium/base/threading/thread_checker.h @@ -5,8 +5,8 @@ #ifndef BASE_THREADING_THREAD_CHECKER_H_ #define BASE_THREADING_THREAD_CHECKER_H_ +#include "base/check.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "base/strings/string_piece.h" #include "base/thread_annotations.h" #include "base/threading/thread_checker_impl.h" @@ -84,7 +84,7 @@ #define DETACH_FROM_THREAD(name) (name).DetachFromThread() #else // DCHECK_IS_ON() #define THREAD_CHECKER(name) static_assert(true, "") -#define DCHECK_CALLED_ON_VALID_THREAD(name, ...) EAT_STREAM_PARAMETERS +#define DCHECK_CALLED_ON_VALID_THREAD(name, ...) EAT_CHECK_STREAM_PARAMS() #define DETACH_FROM_THREAD(name) #endif // DCHECK_IS_ON() diff --git a/chromium/base/threading/thread_checker_unittest.cc b/chromium/base/threading/thread_checker_unittest.cc index d1958896b0d..b6d4b9fb7fb 100644 --- a/chromium/base/threading/thread_checker_unittest.cc +++ b/chromium/base/threading/thread_checker_unittest.cc @@ -15,6 +15,7 @@ #include "base/test/gtest_util.h" #include "base/test/test_simple_task_runner.h" #include "base/threading/simple_thread.h" +#include "base/threading/thread_local.h" #include "base/threading/thread_task_runner_handle.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/base/threading/thread_local.h b/chromium/base/threading/thread_local.h index f9762050b68..d1ab40a152c 100644 --- a/chromium/base/threading/thread_local.h +++ b/chromium/base/threading/thread_local.h @@ -51,7 +51,7 @@ #include <memory> -#include "base/logging.h" +#include "base/check_op.h" #include "base/macros.h" #include "base/threading/thread_local_internal.h" #include "base/threading/thread_local_storage.h" diff --git a/chromium/base/threading/thread_restrictions.cc b/chromium/base/threading/thread_restrictions.cc index c7f07d26646..16e70800f64 100644 --- a/chromium/base/threading/thread_restrictions.cc +++ b/chromium/base/threading/thread_restrictions.cc @@ -4,7 +4,7 @@ #include "base/threading/thread_restrictions.h" -#include "base/trace_event/trace_event.h" +#include "base/trace_event/base_tracing.h" #if DCHECK_IS_ON() diff --git a/chromium/base/threading/thread_restrictions.h b/chromium/base/threading/thread_restrictions.h index 33df64f30e8..29a68a6b15b 100644 --- a/chromium/base/threading/thread_restrictions.h +++ b/chromium/base/threading/thread_restrictions.h @@ -6,9 +6,9 @@ #define BASE_THREADING_THREAD_RESTRICTIONS_H_ #include "base/base_export.h" +#include "base/check_op.h" #include "base/gtest_prod_util.h" #include "base/location.h" -#include "base/logging.h" #include "base/macros.h" // ----------------------------------------------------------------------------- @@ -112,6 +112,7 @@ namespace audio { class OutputDevice; } namespace blink { +class DiskDataAllocator; class RTCVideoDecoderAdapter; class RTCVideoEncoder; class SourceStream; @@ -195,6 +196,9 @@ class PaintCanvasVideoRenderer; namespace memory_instrumentation { class OSMetrics; } +namespace metrics { +class AndroidMetricsServiceClient; +} namespace midi { class TaskService; // https://crbug.com/796830 } @@ -367,6 +371,7 @@ class BASE_EXPORT ScopedAllowBlocking { friend class AdjustOOMScoreHelper; friend class StackSamplingProfiler; friend class android_webview::ScopedAllowInitGLBindings; + friend class blink::DiskDataAllocator; friend class chromeos::MojoUtils; // http://crbug.com/1055467 friend class content::BrowserProcessSubThread; friend class content::PepperPrintSettingsManagerImpl; @@ -376,6 +381,7 @@ class BASE_EXPORT ScopedAllowBlocking { friend class cronet::CronetPrefsManager; friend class cronet::CronetURLRequestContext; friend class memory_instrumentation::OSMetrics; + friend class metrics::AndroidMetricsServiceClient; friend class module_installer::ScopedAllowModulePakLoad; friend class mojo::CoreLibraryInitializer; friend class printing::LocalPrinterHandlerDefault; diff --git a/chromium/base/threading/thread_unittest.cc b/chromium/base/threading/thread_unittest.cc index 68a7685fb72..4f0c46f3507 100644 --- a/chromium/base/threading/thread_unittest.cc +++ b/chromium/base/threading/thread_unittest.cc @@ -12,6 +12,7 @@ #include "base/bind.h" #include "base/debug/leak_annotations.h" +#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/run_loop.h" |