Chromium Code Reviews| Index: base/task_scheduler/scheduler_thread_pool_impl.cc |
| diff --git a/base/task_scheduler/scheduler_thread_pool_impl.cc b/base/task_scheduler/scheduler_thread_pool_impl.cc |
| index dc88a871b6e35b2e3d2df8a4a569f991f2dff1ac..32ba097b888664adbb2cf8509d141b88f73afaae 100644 |
| --- a/base/task_scheduler/scheduler_thread_pool_impl.cc |
| +++ b/base/task_scheduler/scheduler_thread_pool_impl.cc |
| @@ -13,8 +13,10 @@ |
| #include "base/memory/ptr_util.h" |
| #include "base/sequenced_task_runner.h" |
| #include "base/single_thread_task_runner.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/task_scheduler/delayed_task_manager.h" |
| #include "base/task_scheduler/task_tracker.h" |
| +#include "base/threading/platform_thread.h" |
| #include "base/threading/thread_local.h" |
| #include "base/threading/thread_restrictions.h" |
| @@ -180,11 +182,13 @@ class SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl |
| // |re_enqueue_sequence_callback| is invoked when ReEnqueueSequence() is |
| // called with a non-single-threaded Sequence. |shared_priority_queue| is a |
| // PriorityQueue whose transactions may overlap with the worker thread's |
| - // single-threaded PriorityQueue's transactions. |
| + // single-threaded PriorityQueue's transactions. |index| will be appended to |
| + // this thread's name to uniquely identify it. |
| SchedulerWorkerThreadDelegateImpl( |
| SchedulerThreadPoolImpl* outer, |
| const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, |
| - const PriorityQueue* shared_priority_queue); |
| + const PriorityQueue* shared_priority_queue, |
| + size_t index); |
| ~SchedulerWorkerThreadDelegateImpl() override; |
| PriorityQueue* single_threaded_priority_queue() { |
| @@ -208,6 +212,8 @@ class SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl |
| // |single_threaded_priority_queue_|. |
| bool last_sequence_is_single_threaded_ = false; |
| + const size_t index_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThreadDelegateImpl); |
| }; |
| @@ -219,6 +225,7 @@ SchedulerThreadPoolImpl::~SchedulerThreadPoolImpl() { |
| // static |
| std::unique_ptr<SchedulerThreadPoolImpl> SchedulerThreadPoolImpl::Create( |
| + StringPiece name, |
| ThreadPriority thread_priority, |
| size_t max_threads, |
| IORestriction io_restriction, |
| @@ -226,7 +233,7 @@ std::unique_ptr<SchedulerThreadPoolImpl> SchedulerThreadPoolImpl::Create( |
| TaskTracker* task_tracker, |
| DelayedTaskManager* delayed_task_manager) { |
| std::unique_ptr<SchedulerThreadPoolImpl> thread_pool( |
| - new SchedulerThreadPoolImpl(io_restriction, task_tracker, |
| + new SchedulerThreadPoolImpl(name, io_restriction, task_tracker, |
| delayed_task_manager)); |
| if (thread_pool->Initialize(thread_priority, max_threads, |
| re_enqueue_sequence_callback)) { |
| @@ -368,10 +375,12 @@ SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl:: |
| SchedulerWorkerThreadDelegateImpl( |
| SchedulerThreadPoolImpl* outer, |
| const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, |
| - const PriorityQueue* shared_priority_queue) |
| + const PriorityQueue* shared_priority_queue, |
| + size_t index) |
| : outer_(outer), |
| re_enqueue_sequence_callback_(re_enqueue_sequence_callback), |
| - single_threaded_priority_queue_(shared_priority_queue) {} |
| + single_threaded_priority_queue_(shared_priority_queue), |
| + index_(index) {} |
| SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl:: |
| ~SchedulerWorkerThreadDelegateImpl() = default; |
| @@ -385,6 +394,9 @@ void SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl::OnMainEntry( |
| DCHECK(ContainsWorkerThread(outer_->worker_threads_, worker_thread)); |
| #endif |
| + PlatformThread::SetName(StringPrintf("%sWorker%u/%d", outer_->name_.c_str(), |
| + index_, PlatformThread::CurrentId())); |
|
fdoray
2016/05/03 19:01:50
Why is it useful to have index + thread id? I thin
robliao
2016/05/03 23:35:38
Doesn't the debugger generate this for you too?
0:
gab
2016/05/04 18:11:37
Agreed, I initially added the index to have a uniq
|
| + |
| DCHECK(!tls_current_worker_thread.Get().Get()); |
| DCHECK(!tls_current_thread_pool.Get().Get()); |
| tls_current_worker_thread.Get().Set(worker_thread); |
| @@ -466,10 +478,12 @@ void SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl:: |
| } |
| SchedulerThreadPoolImpl::SchedulerThreadPoolImpl( |
| + StringPiece name, |
| IORestriction io_restriction, |
| TaskTracker* task_tracker, |
| DelayedTaskManager* delayed_task_manager) |
| - : io_restriction_(io_restriction), |
| + : name_(name.as_string()), |
| + io_restriction_(io_restriction), |
| idle_worker_threads_stack_lock_(shared_priority_queue_.container_lock()), |
| idle_worker_threads_stack_cv_for_testing_( |
| idle_worker_threads_stack_lock_.CreateConditionVariable()), |
| @@ -494,9 +508,9 @@ bool SchedulerThreadPoolImpl::Initialize( |
| for (size_t i = 0; i < max_threads; ++i) { |
| std::unique_ptr<SchedulerWorkerThread> worker_thread = |
| SchedulerWorkerThread::Create( |
| - thread_priority, |
| - WrapUnique(new SchedulerWorkerThreadDelegateImpl( |
| - this, re_enqueue_sequence_callback, &shared_priority_queue_)), |
| + thread_priority, WrapUnique(new SchedulerWorkerThreadDelegateImpl( |
| + this, re_enqueue_sequence_callback, |
| + &shared_priority_queue_, i)), |
| task_tracker_); |
| if (!worker_thread) |
| break; |