#![warn(missing_docs)]
#[cfg(unix)]
extern crate libc;
#[cfg(windows)]
extern crate winapi;
#[cfg(target_os = "redox")]
extern crate syscall;
#[inline]
pub fn get() -> usize {
get_internal()
}
#[cfg(unix)]
#[inline]
fn get_internal() -> usize {
unsafe { libc::pthread_self() as usize }
}
#[cfg(windows)]
#[inline]
fn get_internal() -> usize {
unsafe { winapi::um::processthreadsapi::GetCurrentThreadId() as usize }
}
#[cfg(target_os = "redox")]
#[inline]
fn get_internal() -> usize {
syscall::getpid().unwrap()
}
#[test]
fn distinct_threads_have_distinct_ids() {
use std::sync::mpsc;
use std::thread;
let (tx, rx) = mpsc::channel();
thread::spawn(move || tx.send(::get()).unwrap()).join().unwrap();
let main_tid = ::get();
let other_tid = rx.recv().unwrap();
assert!(main_tid != other_tid);
}