summaryrefslogtreecommitdiff
path: root/chromium/base/threading
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2013-12-11 21:33:03 +0100
committerAndras Becsi <andras.becsi@digia.com>2013-12-13 12:34:07 +0100
commitf2a33ff9cbc6d19943f1c7fbddd1f23d23975577 (patch)
tree0586a32aa390ade8557dfd6b4897f43a07449578 /chromium/base/threading
parent5362912cdb5eea702b68ebe23702468d17c3017a (diff)
downloadqtwebengine-chromium-f2a33ff9cbc6d19943f1c7fbddd1f23d23975577.tar.gz
Update Chromium to branch 1650 (31.0.1650.63)
Change-Id: I57d8c832eaec1eb2364e0a8e7352a6dd354db99f Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'chromium/base/threading')
-rw-r--r--chromium/base/threading/platform_thread_linux.cc44
-rw-r--r--chromium/base/threading/platform_thread_posix.cc2
-rw-r--r--chromium/base/threading/platform_thread_win.cc7
-rw-r--r--chromium/base/threading/post_task_and_reply_impl.cc7
-rw-r--r--chromium/base/threading/sequenced_worker_pool.cc2
-rw-r--r--chromium/base/threading/thread.cc26
-rw-r--r--chromium/base/threading/thread_id_name_manager.cc3
-rw-r--r--chromium/base/threading/thread_restrictions.h4
-rw-r--r--chromium/base/threading/worker_pool.cc7
9 files changed, 65 insertions, 37 deletions
diff --git a/chromium/base/threading/platform_thread_linux.cc b/chromium/base/threading/platform_thread_linux.cc
index 80227c32079..6d46de4cf26 100644
--- a/chromium/base/threading/platform_thread_linux.cc
+++ b/chromium/base/threading/platform_thread_linux.cc
@@ -27,19 +27,15 @@ namespace base {
namespace {
int ThreadNiceValue(ThreadPriority priority) {
- static const int threadPriorityAudio = -10;
- static const int threadPriorityBackground = 10;
- static const int threadPriorityDefault = 0;
- static const int threadPriorityDisplay = -6;
switch (priority) {
case kThreadPriority_RealtimeAudio:
- return threadPriorityAudio;
+ return -10;
case kThreadPriority_Background:
- return threadPriorityBackground;
+ return 10;
case kThreadPriority_Normal:
- return threadPriorityDefault;
+ return 0;
case kThreadPriority_Display:
- return threadPriorityDisplay;
+ return -6;
default:
NOTREACHED() << "Unknown priority.";
return 0;
@@ -52,7 +48,7 @@ void PlatformThread::SetName(const char* name) {
ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
tracked_objects::ThreadData::InitializeThreadContext(name);
-#ifndef OS_NACL
+#if !defined(OS_NACL)
// On linux we can get the thread names to show up in the debugger by setting
// the process name for the LWP. We don't want to do this for the main
// thread because that would rename the process, causing tools like killall
@@ -69,7 +65,7 @@ void PlatformThread::SetName(const char* name) {
// We expect EPERM failures in sandboxed processes, just ignore those.
if (err < 0 && errno != EPERM)
DPLOG(ERROR) << "prctl(PR_SET_NAME)";
-#endif
+#endif // !defined(OS_NACL)
}
// static
@@ -77,13 +73,8 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
ThreadPriority priority) {
#if !defined(OS_NACL)
if (priority == kThreadPriority_RealtimeAudio) {
- const int kRealTimePrio = 8;
-
- struct sched_param sched_param;
- memset(&sched_param, 0, sizeof(sched_param));
- sched_param.sched_priority = kRealTimePrio;
-
- if (pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param) == 0) {
+ const struct sched_param kRealTimePrio = { 8 };
+ if (pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0) {
// Got real time priority, no need to set nice level.
return;
}
@@ -94,20 +85,19 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
// process. Setting this priority will only succeed if the user has been
// granted permission to adjust nice values on the system.
DCHECK_NE(handle.id_, kInvalidThreadId);
- int kNiceSetting = ThreadNiceValue(priority);
- if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting))
- LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting;
-#endif // !OS_NACL
+ const int kNiceSetting = ThreadNiceValue(priority);
+ if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) {
+ DVPLOG(1) << "Failed to set nice value of thread ("
+ << handle.id_ << ") to " << kNiceSetting;
+ }
+#endif // !defined(OS_NACL)
}
-void InitThreading() {
-}
+void InitThreading() {}
-void InitOnThread() {
-}
+void InitOnThread() {}
-void TerminateOnThread() {
-}
+void TerminateOnThread() {}
size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
return 0;
diff --git a/chromium/base/threading/platform_thread_posix.cc b/chromium/base/threading/platform_thread_posix.cc
index 43a42eca98a..392d4613369 100644
--- a/chromium/base/threading/platform_thread_posix.cc
+++ b/chromium/base/threading/platform_thread_posix.cc
@@ -225,7 +225,7 @@ void PlatformThread::Join(PlatformThreadHandle thread_handle) {
// the thread referred to by |thread_handle| may still be running long-lived /
// blocking tasks.
base::ThreadRestrictions::AssertIOAllowed();
- pthread_join(thread_handle.handle_, NULL);
+ CHECK_EQ(0, pthread_join(thread_handle.handle_, NULL));
}
} // namespace base
diff --git a/chromium/base/threading/platform_thread_win.cc b/chromium/base/threading/platform_thread_win.cc
index cf1e0f60ea1..e9752ba2139 100644
--- a/chromium/base/threading/platform_thread_win.cc
+++ b/chromium/base/threading/platform_thread_win.cc
@@ -135,7 +135,12 @@ void PlatformThread::YieldCurrentThread() {
// static
void PlatformThread::Sleep(TimeDelta duration) {
- ::Sleep(duration.InMillisecondsRoundedUp());
+ // When measured with a high resolution clock, Sleep() sometimes returns much
+ // too early. We may need to call it repeatedly to get the desired duration.
+ TimeTicks end = TimeTicks::Now() + duration;
+ TimeTicks now;
+ while ((now = TimeTicks::Now()) < end)
+ ::Sleep((end - now).InMillisecondsRoundedUp());
}
// static
diff --git a/chromium/base/threading/post_task_and_reply_impl.cc b/chromium/base/threading/post_task_and_reply_impl.cc
index f464c6acad2..a82a4fd8043 100644
--- a/chromium/base/threading/post_task_and_reply_impl.cc
+++ b/chromium/base/threading/post_task_and_reply_impl.cc
@@ -6,7 +6,8 @@
#include "base/bind.h"
#include "base/location.h"
-#include "base/message_loop/message_loop_proxy.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
namespace base {
@@ -26,7 +27,7 @@ class PostTaskAndReplyRelay {
PostTaskAndReplyRelay(const tracked_objects::Location& from_here,
const Closure& task, const Closure& reply)
: from_here_(from_here),
- origin_loop_(MessageLoopProxy::current()) {
+ origin_loop_(ThreadTaskRunnerHandle::Get()) {
task_ = task;
reply_ = reply;
}
@@ -61,7 +62,7 @@ class PostTaskAndReplyRelay {
}
tracked_objects::Location from_here_;
- scoped_refptr<MessageLoopProxy> origin_loop_;
+ scoped_refptr<SingleThreadTaskRunner> origin_loop_;
Closure reply_;
Closure task_;
};
diff --git a/chromium/base/threading/sequenced_worker_pool.cc b/chromium/base/threading/sequenced_worker_pool.cc
index d9921689fe8..4fc090d1186 100644
--- a/chromium/base/threading/sequenced_worker_pool.cc
+++ b/chromium/base/threading/sequenced_worker_pool.cc
@@ -219,7 +219,7 @@ uint64 GetTaskTraceID(const SequencedTask& task,
}
base::LazyInstance<base::ThreadLocalPointer<
- SequencedWorkerPool::SequenceToken> > g_lazy_tls_ptr =
+ SequencedWorkerPool::SequenceToken> >::Leaky g_lazy_tls_ptr =
LAZY_INSTANCE_INITIALIZER;
} // namespace
diff --git a/chromium/base/threading/thread.cc b/chromium/base/threading/thread.cc
index 00f303d3609..f0337750356 100644
--- a/chromium/base/threading/thread.cc
+++ b/chromium/base/threading/thread.cc
@@ -5,6 +5,7 @@
#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"
@@ -172,15 +173,30 @@ 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.
- MessageLoop message_loop(startup_data_->options.message_loop_type);
+ // 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));
// Complete the initialization of our Thread object.
thread_id_ = PlatformThread::CurrentId();
PlatformThread::SetName(name_.c_str());
ANNOTATE_THREAD_NAME(name_.c_str()); // Tell the name to race detector.
- message_loop.set_thread_name(name_);
- message_loop_ = &message_loop;
+ message_loop->set_thread_name(name_);
+ message_loop_ = message_loop.get();
#if defined(OS_WIN)
scoped_ptr<win::ScopedCOMInitializer> com_initializer;
@@ -215,6 +231,10 @@ 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_id_name_manager.cc b/chromium/base/threading/thread_id_name_manager.cc
index ef08548f2ed..7c85c1b5e99 100644
--- a/chromium/base/threading/thread_id_name_manager.cc
+++ b/chromium/base/threading/thread_id_name_manager.cc
@@ -20,7 +20,8 @@ static std::string* g_default_name;
}
ThreadIdNameManager::ThreadIdNameManager()
- : main_process_id_(kInvalidThreadId) {
+ : main_process_name_(NULL),
+ main_process_id_(kInvalidThreadId) {
g_default_name = new std::string(kDefaultName);
AutoLock locked(lock_);
diff --git a/chromium/base/threading/thread_restrictions.h b/chromium/base/threading/thread_restrictions.h
index 595b97060e0..f52e64cf6dd 100644
--- a/chromium/base/threading/thread_restrictions.h
+++ b/chromium/base/threading/thread_restrictions.h
@@ -42,9 +42,11 @@ class Predictor;
}
namespace content {
class BrowserGpuChannelHostFactory;
+class BrowserShutdownProfileDumper;
class BrowserTestBase;
class GLHelper;
class GpuChannelHost;
+class NestedMessagePumpAndroid;
class RenderWidgetHelper;
class ScopedAllowWaitForAndroidLayoutTests;
class TextInputClientMac;
@@ -175,7 +177,9 @@ class BASE_EXPORT ThreadRestrictions {
private:
// DO NOT ADD ANY OTHER FRIEND STATEMENTS, talk to jam or brettw first.
// BEGIN ALLOWED USAGE.
+ friend class content::BrowserShutdownProfileDumper;
friend class content::BrowserTestBase;
+ friend class content::NestedMessagePumpAndroid;
friend class content::RenderWidgetHelper;
friend class content::ScopedAllowWaitForAndroidLayoutTests;
friend class ::HistogramSynchronizer;
diff --git a/chromium/base/threading/worker_pool.cc b/chromium/base/threading/worker_pool.cc
index 9e45f8c89b8..9e5e64c7f97 100644
--- a/chromium/base/threading/worker_pool.cc
+++ b/chromium/base/threading/worker_pool.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
+#include "base/debug/leak_annotations.h"
#include "base/lazy_instance.h"
#include "base/task_runner.h"
#include "base/threading/post_task_and_reply_impl.h"
@@ -104,6 +105,12 @@ bool WorkerPool::PostTaskAndReply(const tracked_objects::Location& from_here,
const Closure& task,
const Closure& reply,
bool task_is_slow) {
+ // Do not report PostTaskAndReplyRelay leaks in tests. There's nothing we can
+ // do about them because WorkerPool doesn't have a flushing API.
+ // http://crbug.com/248513
+ // http://crbug.com/290897
+ // Note: this annotation does not cover tasks posted through a TaskRunner.
+ ANNOTATE_SCOPED_MEMORY_LEAK;
return PostTaskAndReplyWorkerPool(task_is_slow).PostTaskAndReply(
from_here, task, reply);
}