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

Side by Side Diff: base/message_loop/message_loop.cc

Issue 873393004: [Windows] Fix for Browser IO MessageLoop spinning the CPU. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move constant out of platform-specific region of file. Created 5 years, 11 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
11 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_pump_default.h" 15 #include "base/message_loop/message_pump_default.h"
15 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
16 #include "base/metrics/statistics_recorder.h" 17 #include "base/metrics/statistics_recorder.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
(...skipping 18 matching lines...) Expand all
36 37
37 namespace base { 38 namespace base {
38 39
39 namespace { 40 namespace {
40 41
41 // A lazily created thread local storage for quick access to a thread's message 42 // A lazily created thread local storage for quick access to a thread's message
42 // loop, if one exists. This should be safe and free of static constructors. 43 // loop, if one exists. This should be safe and free of static constructors.
43 LazyInstance<base::ThreadLocalPointer<MessageLoop> >::Leaky lazy_tls_ptr = 44 LazyInstance<base::ThreadLocalPointer<MessageLoop> >::Leaky lazy_tls_ptr =
44 LAZY_INSTANCE_INITIALIZER; 45 LAZY_INSTANCE_INITIALIZER;
45 46
47 // Delays larger than this many microseconds are likely bogus, and a warning
48 // should be emitted in debug builds to warn developers.
49 // http://crbug.com/450045
50 const int kTaskDelayWarningThresholdInMicroseconds =
51 std::numeric_limits<int>::max() / 2;
52
46 // Logical events for Histogram profiling. Run with -message-loop-histogrammer 53 // Logical events for Histogram profiling. Run with -message-loop-histogrammer
47 // to get an accounting of messages and actions taken on each thread. 54 // to get an accounting of messages and actions taken on each thread.
48 const int kTaskRunEvent = 0x1; 55 const int kTaskRunEvent = 0x1;
49 #if !defined(OS_NACL) 56 #if !defined(OS_NACL)
50 const int kTimerEvent = 0x2; 57 const int kTimerEvent = 0x2;
51 58
52 // Provide range of message IDs for use in histogramming and debug display. 59 // Provide range of message IDs for use in histogramming and debug display.
53 const int kLeastNonZeroMessageId = 1; 60 const int kLeastNonZeroMessageId = 1;
54 const int kMaxMessageId = 1099; 61 const int kMaxMessageId = 1099;
55 const int kNumberOfDistinctMessagesDisplayed = 1100; 62 const int kNumberOfDistinctMessagesDisplayed = 1100;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 const Closure& task) { 275 const Closure& task) {
269 DCHECK(!task.is_null()) << from_here.ToString(); 276 DCHECK(!task.is_null()) << from_here.ToString();
270 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), true); 277 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), true);
271 } 278 }
272 279
273 void MessageLoop::PostDelayedTask( 280 void MessageLoop::PostDelayedTask(
274 const tracked_objects::Location& from_here, 281 const tracked_objects::Location& from_here,
275 const Closure& task, 282 const Closure& task,
276 TimeDelta delay) { 283 TimeDelta delay) {
277 DCHECK(!task.is_null()) << from_here.ToString(); 284 DCHECK(!task.is_null()) << from_here.ToString();
285 DLOG_IF(WARNING,
286 delay.InMicroseconds() > kTaskDelayWarningThresholdInMicroseconds)
287 << "Requesting super-long task delay period of " << delay.InMicroseconds()
288 << " usec from " << from_here.ToString();
278 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, true); 289 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, true);
279 } 290 }
280 291
281 void MessageLoop::PostNonNestableTask( 292 void MessageLoop::PostNonNestableTask(
282 const tracked_objects::Location& from_here, 293 const tracked_objects::Location& from_here,
283 const Closure& task) { 294 const Closure& task) {
284 DCHECK(!task.is_null()) << from_here.ToString(); 295 DCHECK(!task.is_null()) << from_here.ToString();
285 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), false); 296 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), false);
286 } 297 }
287 298
288 void MessageLoop::PostNonNestableDelayedTask( 299 void MessageLoop::PostNonNestableDelayedTask(
289 const tracked_objects::Location& from_here, 300 const tracked_objects::Location& from_here,
290 const Closure& task, 301 const Closure& task,
291 TimeDelta delay) { 302 TimeDelta delay) {
292 DCHECK(!task.is_null()) << from_here.ToString(); 303 DCHECK(!task.is_null()) << from_here.ToString();
304 DLOG_IF(WARNING,
305 delay.InMicroseconds() > kTaskDelayWarningThresholdInMicroseconds)
306 << "Requesting super-long task delay period of " << delay.InMicroseconds()
307 << " usec from " << from_here.ToString();
293 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, false); 308 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, false);
darin (slow to review) 2015/01/27 07:52:39 would it be better to move this DLOG_IF to the imp
294 } 309 }
295 310
296 void MessageLoop::Run() { 311 void MessageLoop::Run() {
297 RunLoop run_loop; 312 RunLoop run_loop;
298 run_loop.Run(); 313 run_loop.Run();
299 } 314 }
300 315
301 void MessageLoop::RunUntilIdle() { 316 void MessageLoop::RunUntilIdle() {
302 RunLoop run_loop; 317 RunLoop run_loop;
303 run_loop.RunUntilIdle(); 318 run_loop.RunUntilIdle();
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 persistent, 714 persistent,
700 mode, 715 mode,
701 controller, 716 controller,
702 delegate); 717 delegate);
703 } 718 }
704 #endif 719 #endif
705 720
706 #endif // !defined(OS_NACL_SFI) 721 #endif // !defined(OS_NACL_SFI)
707 722
708 } // namespace base 723 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/message_loop/message_pump_win.cc » ('j') | base/message_loop/message_pump_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698