Skip to content

Commit

Permalink
Update energymon dependencies.
Browse files Browse the repository at this point in the history
Ensure the energymon is enabled before trying to get refresh interval.
  • Loading branch information
connorimes committed Oct 28, 2015
1 parent 484c0e4 commit 965fbbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/profile_traits/Cargo.toml
Expand Up @@ -19,7 +19,7 @@ features = [ "serde_serialization" ]

[dependencies.energymon]
git = "https://github.com/energymon/energymon-rust.git"
rev = "67f74732ac"
rev = "eba1d8a"
optional = true

[dependencies.energy-monitor]
Expand Down
9 changes: 7 additions & 2 deletions components/profile_traits/energy.rs
Expand Up @@ -36,8 +36,8 @@ mod energymon {

static mut EM: Option<*mut EnergyMon> = None;

/// Read energy from the energy monitor, otherwise return 0.
pub fn read_energy_uj() -> u64 {
fn init() {
// can't use lazy_static macro for EM (no Sync trait for EnergyMon)
static ONCE: Once = ONCE_INIT;
ONCE.call_once(|| {
if let Ok(em) = EnergyMon::new() {
Expand All @@ -47,14 +47,19 @@ mod energymon {
}
}
});
}

/// Read energy from the energy monitor, otherwise return 0.
pub fn read_energy_uj() -> u64 {
init();
unsafe {
// EnergyMon implementations of EnergyMonitor always return a value
EM.map_or(0, |em| (*em).read_uj().unwrap())
}
}

pub fn get_min_interval_ms() -> u32 {
init();
unsafe {
EM.map_or(0, |em| ((*em).interval_us() as f64 / 1000.0).ceil() as u32)
}
Expand Down
11 changes: 5 additions & 6 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 965fbbd

Please sign in to comment.