Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: base/message_loop.cc

Issue 6780035: Use lock-free lazy initialization for static histogram references (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/message_loop.h ('k') | base/metrics/histogram.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop.h" 5 #include "base/message_loop.h"
6 6
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) 7 #if defined(OS_POSIX) && !defined(OS_MACOSX)
8 #include <gdk/gdk.h> 8 #include <gdk/gdk.h>
9 #include <gdk/gdkx.h> 9 #include <gdk/gdkx.h>
10 #endif 10 #endif
11 11
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 MessageLoop::DestructionObserver::~DestructionObserver() { 116 MessageLoop::DestructionObserver::~DestructionObserver() {
117 } 117 }
118 118
119 //------------------------------------------------------------------------------ 119 //------------------------------------------------------------------------------
120 120
121 MessageLoop::MessageLoop(Type type) 121 MessageLoop::MessageLoop(Type type)
122 : type_(type), 122 : type_(type),
123 nestable_tasks_allowed_(true), 123 nestable_tasks_allowed_(true),
124 exception_restoration_(false), 124 exception_restoration_(false),
125 message_histogram_(NULL),
125 state_(NULL), 126 state_(NULL),
126 #ifdef OS_WIN 127 #ifdef OS_WIN
127 os_modal_loop_(false), 128 os_modal_loop_(false),
128 #endif // OS_WIN 129 #endif // OS_WIN
129 next_sequence_num_(0) { 130 next_sequence_num_(0) {
130 DCHECK(!current()) << "should only have one message loop per thread"; 131 DCHECK(!current()) << "should only have one message loop per thread";
131 lazy_tls_ptr.Pointer()->Set(this); 132 lazy_tls_ptr.Pointer()->Set(this);
132 133
133 // TODO(rvargas): Get rid of the OS guards. 134 // TODO(rvargas): Get rid of the OS guards.
134 #if defined(OS_WIN) 135 #if defined(OS_WIN)
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 // ScheduleWork outside of incoming_queue_lock_. 525 // ScheduleWork outside of incoming_queue_lock_.
525 526
526 pump->ScheduleWork(); 527 pump->ScheduleWork();
527 } 528 }
528 529
529 //------------------------------------------------------------------------------ 530 //------------------------------------------------------------------------------
530 // Method and data for histogramming events and actions taken by each instance 531 // Method and data for histogramming events and actions taken by each instance
531 // on each thread. 532 // on each thread.
532 533
533 void MessageLoop::StartHistogrammer() { 534 void MessageLoop::StartHistogrammer() {
534 if (enable_histogrammer_ && !message_histogram_.get() 535 if (enable_histogrammer_ && !message_histogram_
535 && base::StatisticsRecorder::IsActive()) { 536 && base::StatisticsRecorder::IsActive()) {
536 DCHECK(!thread_name_.empty()); 537 DCHECK(!thread_name_.empty());
537 message_histogram_ = base::LinearHistogram::FactoryGet( 538 message_histogram_ = base::LinearHistogram::FactoryGet(
538 "MsgLoop:" + thread_name_, 539 "MsgLoop:" + thread_name_,
539 kLeastNonZeroMessageId, kMaxMessageId, 540 kLeastNonZeroMessageId, kMaxMessageId,
540 kNumberOfDistinctMessagesDisplayed, 541 kNumberOfDistinctMessagesDisplayed,
541 message_histogram_->kHexRangePrintingFlag); 542 message_histogram_->kHexRangePrintingFlag);
542 message_histogram_->SetRangeDescriptions(event_descriptions_); 543 message_histogram_->SetRangeDescriptions(event_descriptions_);
543 } 544 }
544 } 545 }
545 546
546 void MessageLoop::HistogramEvent(int event) { 547 void MessageLoop::HistogramEvent(int event) {
547 if (message_histogram_.get()) 548 if (message_histogram_)
548 message_histogram_->Add(event); 549 message_histogram_->Add(event);
549 } 550 }
550 551
551 bool MessageLoop::DoWork() { 552 bool MessageLoop::DoWork() {
552 if (!nestable_tasks_allowed_) { 553 if (!nestable_tasks_allowed_) {
553 // Task can't be executed right now. 554 // Task can't be executed right now.
554 return false; 555 return false;
555 } 556 }
556 557
557 for (;;) { 558 for (;;) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 Watcher *delegate) { 717 Watcher *delegate) {
717 return pump_libevent()->WatchFileDescriptor( 718 return pump_libevent()->WatchFileDescriptor(
718 fd, 719 fd,
719 persistent, 720 persistent,
720 static_cast<base::MessagePumpLibevent::Mode>(mode), 721 static_cast<base::MessagePumpLibevent::Mode>(mode),
721 controller, 722 controller,
722 delegate); 723 delegate);
723 } 724 }
724 725
725 #endif 726 #endif
OLDNEW
« no previous file with comments | « base/message_loop.h ('k') | base/metrics/histogram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698