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" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 void MessageLoop::PostTask_Helper( | 275 void MessageLoop::PostTask_Helper( |
276 const tracked_objects::Location& from_here, Task* task, int64 delay_ms, | 276 const tracked_objects::Location& from_here, Task* task, int64 delay_ms, |
277 bool nestable) { | 277 bool nestable) { |
278 task->SetBirthPlace(from_here); | 278 task->SetBirthPlace(from_here); |
279 | 279 |
280 PendingTask pending_task(task, nestable); | 280 PendingTask pending_task(task, nestable); |
281 | 281 |
282 if (delay_ms > 0) { | 282 if (delay_ms > 0) { |
283 pending_task.delayed_run_time = | 283 pending_task.delayed_run_time = |
284 Time::Now() + TimeDelta::FromMilliseconds(delay_ms); | 284 Time::Now() + TimeDelta::FromMilliseconds(delay_ms); |
| 285 |
| 286 #if defined(OS_WIN) |
| 287 if (high_resolution_timer_expiration_.is_null()) { |
| 288 // Windows timers are granular to 15.6ms. If we only set high-res |
| 289 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms, |
| 290 // which as a percentage is pretty inaccurate. So enable high |
| 291 // res timers for any timer which is within 2x of the granularity. |
| 292 // This is a tradeoff between accuracy and power management. |
| 293 bool needs_high_res_timers = |
| 294 delay_ms < (2 * Time::kMinLowResolutionThresholdMs); |
| 295 if (needs_high_res_timers) { |
| 296 Time::ActivateHighResolutionTimer(true); |
| 297 high_resolution_timer_expiration_ = base::TimeTicks::Now() + |
| 298 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs); |
| 299 } |
| 300 } |
| 301 #endif |
285 } else { | 302 } else { |
286 DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; | 303 DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; |
287 } | 304 } |
288 | 305 |
| 306 #if defined(OS_WIN) |
| 307 if (!high_resolution_timer_expiration_.is_null()) { |
| 308 if (base::TimeTicks::Now() > high_resolution_timer_expiration_) { |
| 309 Time::ActivateHighResolutionTimer(false); |
| 310 high_resolution_timer_expiration_ = base::TimeTicks(); |
| 311 } |
| 312 } |
| 313 #endif |
| 314 |
289 // Warning: Don't try to short-circuit, and handle this thread's tasks more | 315 // Warning: Don't try to short-circuit, and handle this thread's tasks more |
290 // directly, as it could starve handling of foreign threads. Put every task | 316 // directly, as it could starve handling of foreign threads. Put every task |
291 // into this queue. | 317 // into this queue. |
292 | 318 |
293 scoped_refptr<base::MessagePump> pump; | 319 scoped_refptr<base::MessagePump> pump; |
294 { | 320 { |
295 AutoLock locked(incoming_queue_lock_); | 321 AutoLock locked(incoming_queue_lock_); |
296 | 322 |
297 bool was_empty = incoming_queue_.empty(); | 323 bool was_empty = incoming_queue_.empty(); |
298 incoming_queue_.push(pending_task); | 324 incoming_queue_.push(pending_task); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 Watcher *delegate) { | 670 Watcher *delegate) { |
645 return pump_libevent()->WatchFileDescriptor( | 671 return pump_libevent()->WatchFileDescriptor( |
646 fd, | 672 fd, |
647 persistent, | 673 persistent, |
648 static_cast<base::MessagePumpLibevent::Mode>(mode), | 674 static_cast<base::MessagePumpLibevent::Mode>(mode), |
649 controller, | 675 controller, |
650 delegate); | 676 delegate); |
651 } | 677 } |
652 | 678 |
653 #endif | 679 #endif |
OLD | NEW |