view src/env_common.rs @ 526:79e0bbc4f604

replace libc usage with fs2, support windows
author João Oliveira <hello@jxs.pt>
date Mon, 18 May 2020 23:43:14 +0100
parents ca98661cf296
children 0c3b736b2781
line wrap: on
line source

use std::thread;
use std::time;

pub fn micros() -> u64 {
    loop {
        let now = time::SystemTime::now().duration_since(time::UNIX_EPOCH);

        match now {
            Err(_) => continue,
            Ok(dur) => return dur.as_secs() * 1000000 + (dur.subsec_nanos() / 1000) as u64,
        }
    }
}

pub fn sleep_for(micros: u32) {
    thread::sleep(time::Duration::new(0, micros * 1000));
}