| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_pump_default.h" | 12 #include "base/message_pump_default.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/thread_local.h" | 14 #include "base/thread_local.h" |
| 15 | 15 |
| 16 #if defined(OS_MACOSX) | 16 #if defined(OS_MACOSX) |
| 17 #include "base/message_pump_mac.h" | 17 #include "base/message_pump_mac.h" |
| 18 #endif | 18 #endif |
| 19 #if defined(OS_POSIX) | 19 #if defined(OS_POSIX) |
| 20 #include "base/message_pump_libevent.h" | 20 #include "base/message_pump_libevent.h" |
| 21 #include "base/third_party/valgrind/valgrind.h" | 21 #include "base/third_party/valgrind/valgrind.h" |
| 22 #endif | 22 #endif |
| 23 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 23 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 24 #include "base/message_pump_glib.h" | 24 #include "base/message_pump_glib.h" |
| 25 #endif | 25 #endif |
| 26 #if defined(TOUCH_UI) | 26 #if defined(TOUCH_UI) |
| 27 #include "base/message_pump_glib_x.h" | 27 #include "base/message_pump_glib_x.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 using base::Time; | |
| 31 using base::TimeDelta; | 30 using base::TimeDelta; |
| 32 using base::TimeTicks; | 31 using base::TimeTicks; |
| 33 | 32 |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 // A lazily created thread local storage for quick access to a thread's message | 35 // A lazily created thread local storage for quick access to a thread's message |
| 37 // loop, if one exists. This should be safe and free of static constructors. | 36 // loop, if one exists. This should be safe and free of static constructors. |
| 38 base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( | 37 base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( |
| 39 base::LINKER_INITIALIZED); | 38 base::LINKER_INITIALIZED); |
| 40 | 39 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms); | 339 TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms); |
| 341 | 340 |
| 342 #if defined(OS_WIN) | 341 #if defined(OS_WIN) |
| 343 if (high_resolution_timer_expiration_.is_null()) { | 342 if (high_resolution_timer_expiration_.is_null()) { |
| 344 // Windows timers are granular to 15.6ms. If we only set high-res | 343 // Windows timers are granular to 15.6ms. If we only set high-res |
| 345 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms, | 344 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms, |
| 346 // which as a percentage is pretty inaccurate. So enable high | 345 // which as a percentage is pretty inaccurate. So enable high |
| 347 // res timers for any timer which is within 2x of the granularity. | 346 // res timers for any timer which is within 2x of the granularity. |
| 348 // This is a tradeoff between accuracy and power management. | 347 // This is a tradeoff between accuracy and power management. |
| 349 bool needs_high_res_timers = | 348 bool needs_high_res_timers = |
| 350 delay_ms < (2 * Time::kMinLowResolutionThresholdMs); | 349 delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs); |
| 351 if (needs_high_res_timers) { | 350 if (needs_high_res_timers) { |
| 352 Time::ActivateHighResolutionTimer(true); | 351 base::Time::ActivateHighResolutionTimer(true); |
| 353 high_resolution_timer_expiration_ = TimeTicks::Now() + | 352 high_resolution_timer_expiration_ = TimeTicks::Now() + |
| 354 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs); | 353 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs); |
| 355 } | 354 } |
| 356 } | 355 } |
| 357 #endif | 356 #endif |
| 358 } else { | 357 } else { |
| 359 DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; | 358 DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; |
| 360 } | 359 } |
| 361 | 360 |
| 362 #if defined(OS_WIN) | 361 #if defined(OS_WIN) |
| 363 if (!high_resolution_timer_expiration_.is_null()) { | 362 if (!high_resolution_timer_expiration_.is_null()) { |
| 364 if (TimeTicks::Now() > high_resolution_timer_expiration_) { | 363 if (TimeTicks::Now() > high_resolution_timer_expiration_) { |
| 365 Time::ActivateHighResolutionTimer(false); | 364 base::Time::ActivateHighResolutionTimer(false); |
| 366 high_resolution_timer_expiration_ = TimeTicks(); | 365 high_resolution_timer_expiration_ = TimeTicks(); |
| 367 } | 366 } |
| 368 } | 367 } |
| 369 #endif | 368 #endif |
| 370 | 369 |
| 371 // Warning: Don't try to short-circuit, and handle this thread's tasks more | 370 // Warning: Don't try to short-circuit, and handle this thread's tasks more |
| 372 // directly, as it could starve handling of foreign threads. Put every task | 371 // directly, as it could starve handling of foreign threads. Put every task |
| 373 // into this queue. | 372 // into this queue. |
| 374 | 373 |
| 375 scoped_refptr<base::MessagePump> pump; | 374 scoped_refptr<base::MessagePump> pump; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 Watcher *delegate) { | 702 Watcher *delegate) { |
| 704 return pump_libevent()->WatchFileDescriptor( | 703 return pump_libevent()->WatchFileDescriptor( |
| 705 fd, | 704 fd, |
| 706 persistent, | 705 persistent, |
| 707 static_cast<base::MessagePumpLibevent::Mode>(mode), | 706 static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 708 controller, | 707 controller, |
| 709 delegate); | 708 delegate); |
| 710 } | 709 } |
| 711 | 710 |
| 712 #endif | 711 #endif |
| OLD | NEW |