OLD | NEW |
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> | |
9 | 8 |
10 #include "base/bind.h" | 9 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
12 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_pump_default.h" | 14 #include "base/message_loop/message_pump_default.h" |
16 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
17 #include "base/metrics/statistics_recorder.h" | 16 #include "base/metrics/statistics_recorder.h" |
18 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
(...skipping 18 matching lines...) Expand all Loading... |
37 | 36 |
38 namespace base { | 37 namespace base { |
39 | 38 |
40 namespace { | 39 namespace { |
41 | 40 |
42 // A lazily created thread local storage for quick access to a thread's message | 41 // A lazily created thread local storage for quick access to a thread's message |
43 // loop, if one exists. This should be safe and free of static constructors. | 42 // loop, if one exists. This should be safe and free of static constructors. |
44 LazyInstance<base::ThreadLocalPointer<MessageLoop> >::Leaky lazy_tls_ptr = | 43 LazyInstance<base::ThreadLocalPointer<MessageLoop> >::Leaky lazy_tls_ptr = |
45 LAZY_INSTANCE_INITIALIZER; | 44 LAZY_INSTANCE_INITIALIZER; |
46 | 45 |
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 | |
53 // Logical events for Histogram profiling. Run with -message-loop-histogrammer | 46 // Logical events for Histogram profiling. Run with -message-loop-histogrammer |
54 // to get an accounting of messages and actions taken on each thread. | 47 // to get an accounting of messages and actions taken on each thread. |
55 const int kTaskRunEvent = 0x1; | 48 const int kTaskRunEvent = 0x1; |
56 #if !defined(OS_NACL) | 49 #if !defined(OS_NACL) |
57 const int kTimerEvent = 0x2; | 50 const int kTimerEvent = 0x2; |
58 | 51 |
59 // Provide range of message IDs for use in histogramming and debug display. | 52 // Provide range of message IDs for use in histogramming and debug display. |
60 const int kLeastNonZeroMessageId = 1; | 53 const int kLeastNonZeroMessageId = 1; |
61 const int kMaxMessageId = 1099; | 54 const int kMaxMessageId = 1099; |
62 const int kNumberOfDistinctMessagesDisplayed = 1100; | 55 const int kNumberOfDistinctMessagesDisplayed = 1100; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 const Closure& task) { | 272 const Closure& task) { |
280 DCHECK(!task.is_null()) << from_here.ToString(); | 273 DCHECK(!task.is_null()) << from_here.ToString(); |
281 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), true); | 274 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), true); |
282 } | 275 } |
283 | 276 |
284 void MessageLoop::PostDelayedTask( | 277 void MessageLoop::PostDelayedTask( |
285 const tracked_objects::Location& from_here, | 278 const tracked_objects::Location& from_here, |
286 const Closure& task, | 279 const Closure& task, |
287 TimeDelta delay) { | 280 TimeDelta delay) { |
288 DCHECK(!task.is_null()) << from_here.ToString(); | 281 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(); | |
293 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, true); | 282 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, true); |
294 } | 283 } |
295 | 284 |
296 void MessageLoop::PostNonNestableTask( | 285 void MessageLoop::PostNonNestableTask( |
297 const tracked_objects::Location& from_here, | 286 const tracked_objects::Location& from_here, |
298 const Closure& task) { | 287 const Closure& task) { |
299 DCHECK(!task.is_null()) << from_here.ToString(); | 288 DCHECK(!task.is_null()) << from_here.ToString(); |
300 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), false); | 289 incoming_task_queue_->AddToIncomingQueue(from_here, task, TimeDelta(), false); |
301 } | 290 } |
302 | 291 |
303 void MessageLoop::PostNonNestableDelayedTask( | 292 void MessageLoop::PostNonNestableDelayedTask( |
304 const tracked_objects::Location& from_here, | 293 const tracked_objects::Location& from_here, |
305 const Closure& task, | 294 const Closure& task, |
306 TimeDelta delay) { | 295 TimeDelta delay) { |
307 DCHECK(!task.is_null()) << from_here.ToString(); | 296 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(); | |
312 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, false); | 297 incoming_task_queue_->AddToIncomingQueue(from_here, task, delay, false); |
313 } | 298 } |
314 | 299 |
315 void MessageLoop::Run() { | 300 void MessageLoop::Run() { |
316 RunLoop run_loop; | 301 RunLoop run_loop; |
317 run_loop.Run(); | 302 run_loop.Run(); |
318 } | 303 } |
319 | 304 |
320 void MessageLoop::RunUntilIdle() { | 305 void MessageLoop::RunUntilIdle() { |
321 RunLoop run_loop; | 306 RunLoop run_loop; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 persistent, | 710 persistent, |
726 mode, | 711 mode, |
727 controller, | 712 controller, |
728 delegate); | 713 delegate); |
729 } | 714 } |
730 #endif | 715 #endif |
731 | 716 |
732 #endif // !defined(OS_NACL_SFI) | 717 #endif // !defined(OS_NACL_SFI) |
733 | 718 |
734 } // namespace base | 719 } // namespace base |
OLD | NEW |