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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 ReloadWorkQueue(); | 172 ReloadWorkQueue(); |
173 // If we end up with empty queues, then break out of the loop. | 173 // If we end up with empty queues, then break out of the loop. |
174 did_work = DeletePendingTasks(); | 174 did_work = DeletePendingTasks(); |
175 if (!did_work) | 175 if (!did_work) |
176 break; | 176 break; |
177 } | 177 } |
178 DCHECK(!did_work); | 178 DCHECK(!did_work); |
179 | 179 |
180 // OK, now make it so that no one can find us. | 180 // OK, now make it so that no one can find us. |
181 lazy_tls_ptr.Pointer()->Set(NULL); | 181 lazy_tls_ptr.Pointer()->Set(NULL); |
182 | |
183 #if defined(OS_WIN) | |
184 // If we left the high-resolution timer activated, deactivate it now. | |
185 // Doing this is not-critical, it is mainly to make sure we track | |
186 // the high resolution timer activations properly in our unit tests. | |
187 if (!high_resolution_timer_expiration_.is_null()) { | |
188 Time::ActivateHighResolutionTimer(false); | |
189 high_resolution_timer_expiration_ = base::TimeTicks(); | |
190 } | |
191 #endif | |
182 } | 192 } |
183 | 193 |
184 void MessageLoop::AddDestructionObserver( | 194 void MessageLoop::AddDestructionObserver( |
185 DestructionObserver* destruction_observer) { | 195 DestructionObserver* destruction_observer) { |
186 DCHECK(this == current()); | 196 DCHECK(this == current()); |
187 destruction_observers_.AddObserver(destruction_observer); | 197 destruction_observers_.AddObserver(destruction_observer); |
188 } | 198 } |
189 | 199 |
190 void MessageLoop::RemoveDestructionObserver( | 200 void MessageLoop::RemoveDestructionObserver( |
191 DestructionObserver* destruction_observer) { | 201 DestructionObserver* destruction_observer) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 #if defined(OS_WIN) | 340 #if defined(OS_WIN) |
331 if (high_resolution_timer_expiration_.is_null()) { | 341 if (high_resolution_timer_expiration_.is_null()) { |
332 // Windows timers are granular to 15.6ms. If we only set high-res | 342 // Windows timers are granular to 15.6ms. If we only set high-res |
333 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms, | 343 // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms, |
334 // which as a percentage is pretty inaccurate. So enable high | 344 // which as a percentage is pretty inaccurate. So enable high |
335 // res timers for any timer which is within 2x of the granularity. | 345 // res timers for any timer which is within 2x of the granularity. |
336 // This is a tradeoff between accuracy and power management. | 346 // This is a tradeoff between accuracy and power management. |
337 bool needs_high_res_timers = | 347 bool needs_high_res_timers = |
338 delay_ms < (2 * Time::kMinLowResolutionThresholdMs); | 348 delay_ms < (2 * Time::kMinLowResolutionThresholdMs); |
339 if (needs_high_res_timers) { | 349 if (needs_high_res_timers) { |
340 Time::ActivateHighResolutionTimer(true); | 350 if (Time::ActivateHighResolutionTimer(true)) { |
341 high_resolution_timer_expiration_ = base::TimeTicks::Now() + | 351 high_resolution_timer_expiration_ = base::TimeTicks::Now() + |
342 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs); | 352 TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs); |
353 } | |
343 } | 354 } |
344 } | 355 } |
345 #endif | 356 #endif |
346 } else { | 357 } else { |
347 DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; | 358 DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; |
348 } | 359 } |
349 | 360 |
350 #if defined(OS_WIN) | 361 #if defined(OS_WIN) |
351 if (!high_resolution_timer_expiration_.is_null()) { | 362 if (!high_resolution_timer_expiration_.is_null()) { |
352 if (base::TimeTicks::Now() > high_resolution_timer_expiration_) { | 363 if (base::TimeTicks::Now() > high_resolution_timer_expiration_) { |
jar (doing other things)
2010/10/20 00:37:19
This will work.... but for all your effort to avoi
| |
353 Time::ActivateHighResolutionTimer(false); | 364 Time::ActivateHighResolutionTimer(false); |
354 high_resolution_timer_expiration_ = base::TimeTicks(); | 365 high_resolution_timer_expiration_ = base::TimeTicks(); |
355 } | 366 } |
356 } | 367 } |
357 #endif | 368 #endif |
358 | 369 |
359 // 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 |
360 // 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 |
361 // into this queue. | 372 // into this queue. |
362 | 373 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 Watcher *delegate) { | 691 Watcher *delegate) { |
681 return pump_libevent()->WatchFileDescriptor( | 692 return pump_libevent()->WatchFileDescriptor( |
682 fd, | 693 fd, |
683 persistent, | 694 persistent, |
684 static_cast<base::MessagePumpLibevent::Mode>(mode), | 695 static_cast<base::MessagePumpLibevent::Mode>(mode), |
685 controller, | 696 controller, |
686 delegate); | 697 delegate); |
687 } | 698 } |
688 | 699 |
689 #endif | 700 #endif |
OLD | NEW |