libdd_common/
threading.rs1#[cfg(target_os = "linux")]
6pub fn get_current_thread_id() -> i64 {
7 unsafe { libc::syscall(libc::SYS_gettid) as i64 }
9}
10
11#[cfg(target_os = "macos")]
13pub fn get_current_thread_id() -> i64 {
14 let mut tid: u64 = 0;
15 let rc = unsafe { libc::pthread_threadid_np(0, &mut tid) };
18 debug_assert_eq!(
19 rc,
20 0,
21 "pthread_threadid_np failed: {rc} ({})",
22 std::io::Error::from_raw_os_error(rc)
23 );
24 tid as i64
25}
26
27#[cfg(target_os = "windows")]
29pub fn get_current_thread_id() -> i64 {
30 unsafe { windows_sys::Win32::System::Threading::GetCurrentThreadId() as i64 }
32}
33
34#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
36compile_error!("libdd_common::threading::get_current_thread_id is unsupported on this platform");