diff options
author | Andras Becsi <andras.becsi@digia.com> | 2014-03-18 13:16:26 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-03-20 15:55:39 +0100 |
commit | 3f0f86b0caed75241fa71c95a5d73bc0164348c5 (patch) | |
tree | 92b9fb00f2e9e90b0be2262093876d4f43b6cd13 /chromium/base/threading | |
parent | e90d7c4b152c56919d963987e2503f9909a666d2 (diff) | |
download | qtwebengine-chromium-3f0f86b0caed75241fa71c95a5d73bc0164348c5.tar.gz |
Update to new stable branch 1750
This also includes an updated ninja and chromium dependencies
needed on Windows.
Change-Id: Icd597d80ed3fa4425933c9f1334c3c2e31291c42
Reviewed-by: Zoltan Arvai <zarvai@inf.u-szeged.hu>
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'chromium/base/threading')
-rw-r--r-- | chromium/base/threading/non_thread_safe.h | 2 | ||||
-rw-r--r-- | chromium/base/threading/sequenced_worker_pool.h | 3 | ||||
-rw-r--r-- | chromium/base/threading/thread.cc | 42 | ||||
-rw-r--r-- | chromium/base/threading/thread.h | 21 | ||||
-rw-r--r-- | chromium/base/threading/thread_checker.h | 2 | ||||
-rw-r--r-- | chromium/base/threading/thread_local.h | 15 | ||||
-rw-r--r-- | chromium/base/threading/thread_local_posix.cc | 12 | ||||
-rw-r--r-- | chromium/base/threading/thread_local_win.cc | 14 | ||||
-rw-r--r-- | chromium/base/threading/watchdog.cc | 38 | ||||
-rw-r--r-- | chromium/base/threading/worker_pool_posix_unittest.cc | 1 |
10 files changed, 84 insertions, 66 deletions
diff --git a/chromium/base/threading/non_thread_safe.h b/chromium/base/threading/non_thread_safe.h index cf7a41818da..a27bb0ea0c5 100644 --- a/chromium/base/threading/non_thread_safe.h +++ b/chromium/base/threading/non_thread_safe.h @@ -56,7 +56,7 @@ class NonThreadSafeDoNothing { // } // // Note that base::ThreadChecker offers identical functionality to -// NonThreadSafe, but does not require inheritence. In general, it is preferable +// NonThreadSafe, but does not require inheritance. In general, it is preferable // to have a base::ThreadChecker as a member, rather than inherit from // NonThreadSafe. For more details about when to choose one over the other, see // the documentation for base::ThreadChecker. diff --git a/chromium/base/threading/sequenced_worker_pool.h b/chromium/base/threading/sequenced_worker_pool.h index 1bd275b206d..d3c85e23ae4 100644 --- a/chromium/base/threading/sequenced_worker_pool.h +++ b/chromium/base/threading/sequenced_worker_pool.h @@ -69,6 +69,9 @@ class SequencedTaskRunner; // // Note that SequencedWorkerPool is RefCountedThreadSafe (inherited // from TaskRunner). +// +// Test-only code should wrap this in a base::SequencedWorkerPoolOwner to avoid +// memory leaks. See http://crbug.com/273800 class BASE_EXPORT SequencedWorkerPool : public TaskRunner { public: // Defines what should happen to a task posted to the worker pool on diff --git a/chromium/base/threading/thread.cc b/chromium/base/threading/thread.cc index f0337750356..ae4d3731947 100644 --- a/chromium/base/threading/thread.cc +++ b/chromium/base/threading/thread.cc @@ -5,7 +5,6 @@ #include "base/threading/thread.h" #include "base/bind.h" -#include "base/debug/alias.h" #include "base/lazy_instance.h" #include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/threading/thread_id_name_manager.h" @@ -50,6 +49,20 @@ struct Thread::StartupData { event(false, false) {} }; +Thread::Options::Options() + : message_loop_type(MessageLoop::TYPE_DEFAULT), + stack_size(0) { +} + +Thread::Options::Options(MessageLoop::Type type, + size_t size) + : message_loop_type(type), + stack_size(size) { +} + +Thread::Options::~Options() { +} + Thread::Thread(const char* name) : #if defined(OS_WIN) @@ -173,23 +186,16 @@ bool Thread::GetThreadWasQuitProperly() { void Thread::ThreadMain() { { -#if defined(OS_MACOSX) - // Store the thread name on the stack to debug <http://crbug.com/274705>. - // End with a byte sequence of <EOT><BEL><NUL> to make it easier to grep in - // the minidump stack dump. - const size_t kThreadNameSize = 50; - char thread_name[kThreadNameSize]; - strncpy(thread_name, name_.c_str(), kThreadNameSize); - thread_name[kThreadNameSize - 1] = '\0'; - thread_name[kThreadNameSize - 2] = '\7'; - thread_name[kThreadNameSize - 3] = '\3'; - base::debug::Alias(thread_name); -#endif - // The message loop for this thread. // Allocated on the heap to centralize any leak reports at this line. - scoped_ptr<MessageLoop> message_loop( - new MessageLoop(startup_data_->options.message_loop_type)); + scoped_ptr<MessageLoop> message_loop; + if (!startup_data_->options.message_pump_factory.is_null()) { + message_loop.reset( + new MessageLoop(startup_data_->options.message_pump_factory.Run())); + } else { + message_loop.reset( + new MessageLoop(startup_data_->options.message_loop_type)); + } // Complete the initialization of our Thread object. thread_id_ = PlatformThread::CurrentId(); @@ -231,10 +237,6 @@ void Thread::ThreadMain() { // We can't receive messages anymore. message_loop_ = NULL; - -#if defined(OS_MACOSX) - base::debug::Alias(thread_name); -#endif } } diff --git a/chromium/base/threading/thread.h b/chromium/base/threading/thread.h index 98831b82e5c..99f9dd4a597 100644 --- a/chromium/base/threading/thread.h +++ b/chromium/base/threading/thread.h @@ -8,12 +8,16 @@ #include <string> #include "base/base_export.h" +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop_proxy.h" #include "base/threading/platform_thread.h" namespace base { +class MessagePump; + // A simple thread abstraction that establishes a MessageLoop on a new thread. // The consumer uses the MessageLoop of the thread to cause code to execute on // the thread. When this object is destroyed the thread is terminated. All @@ -29,14 +33,23 @@ namespace base { // (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop class BASE_EXPORT Thread : PlatformThread::Delegate { public: - struct Options { - Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {} - Options(MessageLoop::Type type, size_t size) - : message_loop_type(type), stack_size(size) {} + struct BASE_EXPORT Options { + typedef Callback<scoped_ptr<MessagePump>()> MessagePumpFactory; + + Options(); + Options(MessageLoop::Type type, size_t size); + ~Options(); // Specifies the type of message loop that will be allocated on the thread. + // This is ignored if message_pump_factory.is_null() is false. MessageLoop::Type message_loop_type; + // Used to create the MessagePump for the MessageLoop. The callback is Run() + // on the thread. If message_pump_factory.is_null(), then a MessagePump + // appropriate for |message_loop_type| is created. Setting this forces the + // MessageLoop::Type to TYPE_CUSTOM. + MessagePumpFactory message_pump_factory; + // Specifies the maximum stack size that the thread is allowed to use. // This does not necessarily correspond to the thread's initial stack size. // A value of 0 indicates that the default maximum should be used. diff --git a/chromium/base/threading/thread_checker.h b/chromium/base/threading/thread_checker.h index 5a8ef2261d7..a2ab3fe4fab 100644 --- a/chromium/base/threading/thread_checker.h +++ b/chromium/base/threading/thread_checker.h @@ -46,7 +46,7 @@ class ThreadCheckerDoNothing { // // While inheriting from base::NonThreadSafe may give a clear indication about // the thread-safety of a class, it may also lead to violations of the style -// guide with regard to multiple inheritence. The choice between having a +// guide with regard to multiple inheritance. The choice between having a // ThreadChecker member and inheriting from base::NonThreadSafe should be based // on whether: // - Derived classes need to know the thread they belong to, as opposed to diff --git a/chromium/base/threading/thread_local.h b/chromium/base/threading/thread_local.h index 6561420758c..b13be1ab467 100644 --- a/chromium/base/threading/thread_local.h +++ b/chromium/base/threading/thread_local.h @@ -56,7 +56,6 @@ #endif namespace base { - namespace internal { // Helper functions that abstract the cross-platform APIs. Do not use directly. @@ -67,10 +66,10 @@ struct BASE_EXPORT ThreadLocalPlatform { typedef pthread_key_t SlotType; #endif - static void AllocateSlot(SlotType& slot); - static void FreeSlot(SlotType& slot); - static void* GetValueFromSlot(SlotType& slot); - static void SetValueInSlot(SlotType& slot, void* value); + static void AllocateSlot(SlotType* slot); + static void FreeSlot(SlotType slot); + static void* GetValueFromSlot(SlotType slot); + static void SetValueInSlot(SlotType slot, void* value); }; } // namespace internal @@ -79,7 +78,7 @@ template <typename Type> class ThreadLocalPointer { public: ThreadLocalPointer() : slot_() { - internal::ThreadLocalPlatform::AllocateSlot(slot_); + internal::ThreadLocalPlatform::AllocateSlot(&slot_); } ~ThreadLocalPointer() { @@ -106,8 +105,8 @@ class ThreadLocalPointer { class ThreadLocalBoolean { public: - ThreadLocalBoolean() { } - ~ThreadLocalBoolean() { } + ThreadLocalBoolean() {} + ~ThreadLocalBoolean() {} bool Get() { return tlp_.Get() != NULL; diff --git a/chromium/base/threading/thread_local_posix.cc b/chromium/base/threading/thread_local_posix.cc index 49510064e75..526a66d0629 100644 --- a/chromium/base/threading/thread_local_posix.cc +++ b/chromium/base/threading/thread_local_posix.cc @@ -9,32 +9,30 @@ #include "base/logging.h" namespace base { - namespace internal { // static -void ThreadLocalPlatform::AllocateSlot(SlotType& slot) { - int error = pthread_key_create(&slot, NULL); +void ThreadLocalPlatform::AllocateSlot(SlotType* slot) { + int error = pthread_key_create(slot, NULL); CHECK_EQ(error, 0); } // static -void ThreadLocalPlatform::FreeSlot(SlotType& slot) { +void ThreadLocalPlatform::FreeSlot(SlotType slot) { int error = pthread_key_delete(slot); DCHECK_EQ(0, error); } // static -void* ThreadLocalPlatform::GetValueFromSlot(SlotType& slot) { +void* ThreadLocalPlatform::GetValueFromSlot(SlotType slot) { return pthread_getspecific(slot); } // static -void ThreadLocalPlatform::SetValueInSlot(SlotType& slot, void* value) { +void ThreadLocalPlatform::SetValueInSlot(SlotType slot, void* value) { int error = pthread_setspecific(slot, value); DCHECK_EQ(error, 0); } } // namespace internal - } // namespace base diff --git a/chromium/base/threading/thread_local_win.cc b/chromium/base/threading/thread_local_win.cc index 56d3a3ac7f2..1c74e421387 100644 --- a/chromium/base/threading/thread_local_win.cc +++ b/chromium/base/threading/thread_local_win.cc @@ -9,34 +9,32 @@ #include "base/logging.h" namespace base { - namespace internal { // static -void ThreadLocalPlatform::AllocateSlot(SlotType& slot) { - slot = TlsAlloc(); - CHECK_NE(slot, TLS_OUT_OF_INDEXES); +void ThreadLocalPlatform::AllocateSlot(SlotType* slot) { + *slot = TlsAlloc(); + CHECK_NE(*slot, TLS_OUT_OF_INDEXES); } // static -void ThreadLocalPlatform::FreeSlot(SlotType& slot) { +void ThreadLocalPlatform::FreeSlot(SlotType slot) { if (!TlsFree(slot)) { NOTREACHED() << "Failed to deallocate tls slot with TlsFree()."; } } // static -void* ThreadLocalPlatform::GetValueFromSlot(SlotType& slot) { +void* ThreadLocalPlatform::GetValueFromSlot(SlotType slot) { return TlsGetValue(slot); } // static -void ThreadLocalPlatform::SetValueInSlot(SlotType& slot, void* value) { +void ThreadLocalPlatform::SetValueInSlot(SlotType slot, void* value) { if (!TlsSetValue(slot, value)) { LOG(FATAL) << "Failed to TlsSetValue()."; } } } // namespace internal - } // namespace base diff --git a/chromium/base/threading/watchdog.cc b/chromium/base/threading/watchdog.cc index a18efecc5f6..82c187564b1 100644 --- a/chromium/base/threading/watchdog.cc +++ b/chromium/base/threading/watchdog.cc @@ -20,14 +20,18 @@ namespace { // Without this safety net, any alarm will typically trigger a host of follow // on alarms from callers that specify old times. -// Lock for access of static data... -LazyInstance<Lock>::Leaky g_static_lock = LAZY_INSTANCE_INITIALIZER; +struct StaticData { + // Lock for access of static data... + Lock lock; -// When did we last alarm and get stuck (for a while) in a debugger? -TimeTicks g_last_debugged_alarm_time; + // When did we last alarm and get stuck (for a while) in a debugger? + TimeTicks last_debugged_alarm_time; -// How long did we sit on a break in the debugger? -TimeDelta g_last_debugged_alarm_delay; + // How long did we sit on a break in the debugger? + TimeDelta last_debugged_alarm_delay; +}; + +LazyInstance<StaticData>::Leaky g_static_data = LAZY_INSTANCE_INITIALIZER; } // namespace @@ -115,6 +119,7 @@ void Watchdog::Alarm() { void Watchdog::ThreadDelegate::ThreadMain() { SetThreadName(); TimeDelta remaining_duration; + StaticData* static_data = g_static_data.Pointer(); while (1) { AutoLock lock(watchdog_->lock_); while (DISARMED == watchdog_->state_) @@ -134,12 +139,12 @@ void Watchdog::ThreadDelegate::ThreadMain() { // We overslept, so this seems like a real alarm. // Watch out for a user that stopped the debugger on a different alarm! { - AutoLock static_lock(*g_static_lock.Pointer()); - if (g_last_debugged_alarm_time > watchdog_->start_time_) { + AutoLock static_lock(static_data->lock); + if (static_data->last_debugged_alarm_time > watchdog_->start_time_) { // False alarm: we started our clock before the debugger break (last // alarm time). - watchdog_->start_time_ += g_last_debugged_alarm_delay; - if (g_last_debugged_alarm_time > watchdog_->start_time_) + watchdog_->start_time_ += static_data->last_debugged_alarm_delay; + if (static_data->last_debugged_alarm_time > watchdog_->start_time_) // Too many alarms must have taken place. watchdog_->state_ = DISARMED; continue; @@ -155,10 +160,10 @@ void Watchdog::ThreadDelegate::ThreadMain() { if (last_alarm_delay <= TimeDelta::FromMilliseconds(2)) continue; // Ignore race of two alarms/breaks going off at roughly the same time. - AutoLock static_lock(*g_static_lock.Pointer()); + AutoLock static_lock(static_data->lock); // This was a real debugger break. - g_last_debugged_alarm_time = last_alarm_time; - g_last_debugged_alarm_delay = last_alarm_delay; + static_data->last_debugged_alarm_time = last_alarm_time; + static_data->last_debugged_alarm_delay = last_alarm_delay; } } @@ -170,9 +175,10 @@ void Watchdog::ThreadDelegate::SetThreadName() const { // static void Watchdog::ResetStaticData() { - AutoLock lock(*g_static_lock.Pointer()); - g_last_debugged_alarm_time = TimeTicks(); - g_last_debugged_alarm_delay = TimeDelta(); + StaticData* static_data = g_static_data.Pointer(); + AutoLock lock(static_data->lock); + static_data->last_debugged_alarm_time = TimeTicks(); + static_data->last_debugged_alarm_delay = TimeDelta(); } } // namespace base diff --git a/chromium/base/threading/worker_pool_posix_unittest.cc b/chromium/base/threading/worker_pool_posix_unittest.cc index 49f6570aa4e..862ffddcf89 100644 --- a/chromium/base/threading/worker_pool_posix_unittest.cc +++ b/chromium/base/threading/worker_pool_posix_unittest.cc @@ -160,7 +160,6 @@ TEST_F(PosixDynamicThreadPoolTest, Basic) { EXPECT_EQ(1U, unique_threads_.size()) << "There should be only one thread allocated for one task."; - EXPECT_EQ(1, peer_.num_idle_threads()); EXPECT_EQ(1, counter_); } |