use libc::{clockid_t, pthread_self, pthread_t};
use std::io::Error;
use std::os::raw::c_int;
use super::PosixClock;
#[link(name = "pthread")]
extern "C" {
fn pthread_getcpuclockid(thread: pthread_t, clock_id: *mut clockid_t) -> c_int;
}
pub type ThreadCPUClock = PosixClock;
pub fn cpu_clock_for_current_thread() -> Result<ThreadCPUClock, Error> {
let mut clockid = 0 as clockid_t;
if unsafe { pthread_getcpuclockid(pthread_self(), &mut clockid) } != 0 {
return Err(Error::last_os_error());
}
let clock = unsafe { ThreadCPUClock::from_clockid(clockid) };
return Ok(clock);
}