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

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

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 years, 10 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 const Closure& task) { 279 const Closure& task) {
273 DCHECK(!task.is_null()) << from_here.ToString(); 280 DCHECK(!task.is_null()) << from_here.ToString();
274 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), true); 281 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), true);
275 } 282 }
276 283
277 void MessageLoop::PostDelayedTask( 284 void MessageLoop::PostDelayedTask(
278 const tracked_objects::Location& from_here, 285 const tracked_objects::Location& from_here,
279 const Closure& task, 286 const Closure& task,
280 TimeDelta delay) { 287 TimeDelta delay) {
281 DCHECK(!task.is_null()) << from_here.ToString(); 288 DCHECK(!task.is_null()) << from_here.ToString();
289 DLOG_IF(WARNING,
290 delay.InMicroseconds() > kTaskDelayWarningThresholdInMicroseconds)
291 << "Requesting super-long task delay period of " << delay.InMicroseconds()
292 << " usec from " << from_here.ToString();
282 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, true); 293 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, true);
283 } 294 }
284 295
285 void MessageLoop::PostNonNestableTask( 296 void MessageLoop::PostNonNestableTask(
286 const tracked_objects::Location& from_here, 297 const tracked_objects::Location& from_here,
287 const Closure& task) { 298 const Closure& task) {
288 DCHECK(!task.is_null()) << from_here.ToString(); 299 DCHECK(!task.is_null()) << from_here.ToString();
289 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), false); 300 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), false);
290 } 301 }
291 302
292 void MessageLoop::PostNonNestableDelayedTask( 303 void MessageLoop::PostNonNestableDelayedTask(
293 const tracked_objects::Location& from_here, 304 const tracked_objects::Location& from_here,
294 const Closure& task, 305 const Closure& task,
295 TimeDelta delay) { 306 TimeDelta delay) {
296 DCHECK(!task.is_null()) << from_here.ToString(); 307 DCHECK(!task.is_null()) << from_here.ToString();
308 DLOG_IF(WARNING,
309 delay.InMicroseconds() > kTaskDelayWarningThresholdInMicroseconds)
310 << "Requesting super-long task delay period of " << delay.InMicroseconds()
311 << " usec from " << from_here.ToString();
297 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, false); 312 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, false);
298 } 313 }
299 314
300 void MessageLoop::Run() { 315 void MessageLoop::Run() {
301 RunLoop run_loop; 316 RunLoop run_loop;
302 run_loop.Run(); 317 run_loop.Run();
303 } 318 }
304 319
305 void MessageLoop::RunUntilIdle() { 320 void MessageLoop::RunUntilIdle() {
306 RunLoop run_loop; 321 RunLoop run_loop;
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 persistent, 725 persistent,
711 mode, 726 mode,
712 controller, 727 controller,
713 delegate); 728 delegate);
714 } 729 }
715 #endif 730 #endif
716 731
717 #endif // !defined(OS_NACL_SFI) 732 #endif // !defined(OS_NACL_SFI)
718 733
719 } // namespace base 734 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_shared_memory_unittest.cc ('k') | base/message_loop/message_pump_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698