Chromium Code Reviews| Index: base/message_loop/message_loop.cc |
| diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc |
| index 7038178079fc1619eec2366fc521c335f4fcadab..f360bcf00fd80d67bea9af6d9579fa1fded74b42 100644 |
| --- a/base/message_loop/message_loop.cc |
| +++ b/base/message_loop/message_loop.cc |
| @@ -18,6 +18,7 @@ |
| #include "base/metrics/statistics_recorder.h" |
| #include "base/run_loop.h" |
| #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| +#include "base/threading/thread_id_name_manager.h" |
| #include "base/threading/thread_local.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| @@ -395,7 +396,8 @@ MessageLoop::MessageLoop(Type type, MessagePumpFactoryCallback pump_factory) |
| incoming_task_queue_(new internal::IncomingTaskQueue(this)), |
| unbound_task_runner_( |
| new internal::MessageLoopTaskRunner(incoming_task_queue_)), |
| - task_runner_(unbound_task_runner_) { |
| + task_runner_(unbound_task_runner_), |
| + thread_id_(kInvalidThreadId) { |
| // If type is TYPE_CUSTOM non-null pump_factory must be given. |
| DCHECK(type_ != TYPE_CUSTOM || !pump_factory_.is_null()); |
| } |
| @@ -413,9 +415,19 @@ void MessageLoop::BindToCurrentThread() { |
| incoming_task_queue_->StartScheduling(); |
| unbound_task_runner_->BindToCurrentThread(); |
| unbound_task_runner_ = nullptr; |
| + thread_id_ = PlatformThread::CurrentId(); |
|
alokp
2016/06/03 16:34:56
Do I need a memory barrier here as well?
gab
2016/06/07 00:30:59
Ah yes, let's put one and scope this code inline f
alokp
2016/06/10 22:13:00
Done.
|
| SetThreadTaskRunnerHandle(); |
| } |
| +std::string MessageLoop::GetThreadName() const { |
| + if (thread_id_ == kInvalidThreadId) { |
| + // |thread_id_| may already have been initialized but this thread might not |
| + // have received the update yet. |
| + subtle::MemoryBarrier(); |
| + } |
| + return ThreadIdNameManager::GetInstance()->GetName(thread_id_); |
| +} |
| + |
| void MessageLoop::SetTaskRunner( |
| scoped_refptr<SingleThreadTaskRunner> task_runner) { |
| DCHECK_EQ(this, current()); |
| @@ -554,13 +566,12 @@ void MessageLoop::StartHistogrammer() { |
| #if !defined(OS_NACL) // NaCl build has no metrics code. |
| if (enable_histogrammer_ && !message_histogram_ |
| && StatisticsRecorder::IsActive()) { |
| - DCHECK(!thread_name_.empty()); |
| + std::string thread_name = GetThreadName(); |
| + DCHECK(!thread_name.empty()); |
| message_histogram_ = LinearHistogram::FactoryGetWithRangeDescription( |
| - "MsgLoop:" + thread_name_, |
| - kLeastNonZeroMessageId, kMaxMessageId, |
| + "MsgLoop:" + thread_name, kLeastNonZeroMessageId, kMaxMessageId, |
| kNumberOfDistinctMessagesDisplayed, |
| - HistogramBase::kHexRangePrintingFlag, |
| - event_descriptions_); |
| + HistogramBase::kHexRangePrintingFlag, event_descriptions_); |
| } |
| #endif |
| } |