mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 655413 - Don't bump timer frequency in the IPC code. r=cjones
This commit is contained in:
parent
7b218c3f48
commit
0edf60727a
@ -227,22 +227,11 @@ DWORD (*tick_function)(void) = &timeGetTimeWrapper;
|
||||
// which will roll over the 32-bit value every ~49 days. We try to track
|
||||
// rollover ourselves, which works if TimeTicks::Now() is called at least every
|
||||
// 49 days.
|
||||
class NowSingleton : public base::SystemMonitor::PowerObserver {
|
||||
class NowSingleton {
|
||||
public:
|
||||
NowSingleton()
|
||||
: rollover_(TimeDelta::FromMilliseconds(0)),
|
||||
last_seen_(0),
|
||||
hi_res_clock_enabled_(false) {
|
||||
base::SystemMonitor* system = base::SystemMonitor::Get();
|
||||
system->AddObserver(this);
|
||||
UseHiResClock(!system->BatteryPower());
|
||||
}
|
||||
|
||||
~NowSingleton() {
|
||||
UseHiResClock(false);
|
||||
base::SystemMonitor* monitor = base::SystemMonitor::Get();
|
||||
if (monitor)
|
||||
monitor->RemoveObserver(this);
|
||||
last_seen_(0) {
|
||||
}
|
||||
|
||||
TimeDelta Now() {
|
||||
@ -256,30 +245,10 @@ class NowSingleton : public base::SystemMonitor::PowerObserver {
|
||||
return TimeDelta::FromMilliseconds(now) + rollover_;
|
||||
}
|
||||
|
||||
// Interfaces for monitoring Power changes.
|
||||
void OnPowerStateChange(base::SystemMonitor* system) {
|
||||
UseHiResClock(!system->BatteryPower());
|
||||
}
|
||||
|
||||
void OnSuspend(base::SystemMonitor* system) {}
|
||||
void OnResume(base::SystemMonitor* system) {}
|
||||
|
||||
private:
|
||||
// Enable or disable the faster multimedia timer.
|
||||
void UseHiResClock(bool enabled) {
|
||||
if (enabled == hi_res_clock_enabled_)
|
||||
return;
|
||||
if (enabled)
|
||||
timeBeginPeriod(1);
|
||||
else
|
||||
timeEndPeriod(1);
|
||||
hi_res_clock_enabled_ = enabled;
|
||||
}
|
||||
|
||||
Lock lock_; // To protected last_seen_ and rollover_.
|
||||
TimeDelta rollover_; // Accumulation of time lost due to rollover.
|
||||
DWORD last_seen_; // The last timeGetTime value we saw, to detect rollover.
|
||||
bool hi_res_clock_enabled_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NowSingleton);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user