13da5c369Sopenharmony_ci//! Low level threading primitives 23da5c369Sopenharmony_ci 33da5c369Sopenharmony_ci#[cfg(not(target_os = "redox"))] 43da5c369Sopenharmony_ciuse crate::errno::Errno; 53da5c369Sopenharmony_ci#[cfg(not(target_os = "redox"))] 63da5c369Sopenharmony_ciuse crate::Result; 73da5c369Sopenharmony_ciuse libc::{self, pthread_t}; 83da5c369Sopenharmony_ci 93da5c369Sopenharmony_ci/// Identifies an individual thread. 103da5c369Sopenharmony_cipub type Pthread = pthread_t; 113da5c369Sopenharmony_ci 123da5c369Sopenharmony_ci/// Obtain ID of the calling thread (see 133da5c369Sopenharmony_ci/// [`pthread_self(3)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html) 143da5c369Sopenharmony_ci/// 153da5c369Sopenharmony_ci/// The thread ID returned by `pthread_self()` is not the same thing as 163da5c369Sopenharmony_ci/// the kernel thread ID returned by a call to `gettid(2)`. 173da5c369Sopenharmony_ci#[inline] 183da5c369Sopenharmony_cipub fn pthread_self() -> Pthread { 193da5c369Sopenharmony_ci unsafe { libc::pthread_self() } 203da5c369Sopenharmony_ci} 213da5c369Sopenharmony_ci 223da5c369Sopenharmony_cifeature! { 233da5c369Sopenharmony_ci#![feature = "signal"] 243da5c369Sopenharmony_ci 253da5c369Sopenharmony_ci/// Send a signal to a thread (see [`pthread_kill(3)`]). 263da5c369Sopenharmony_ci/// 273da5c369Sopenharmony_ci/// If `signal` is `None`, `pthread_kill` will only preform error checking and 283da5c369Sopenharmony_ci/// won't send any signal. 293da5c369Sopenharmony_ci/// 303da5c369Sopenharmony_ci/// [`pthread_kill(3)`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html 313da5c369Sopenharmony_ci#[allow(clippy::not_unsafe_ptr_arg_deref)] 323da5c369Sopenharmony_ci#[cfg(not(target_os = "redox"))] 333da5c369Sopenharmony_cipub fn pthread_kill<T>(thread: Pthread, signal: T) -> Result<()> 343da5c369Sopenharmony_ci where T: Into<Option<crate::sys::signal::Signal>> 353da5c369Sopenharmony_ci{ 363da5c369Sopenharmony_ci let sig = match signal.into() { 373da5c369Sopenharmony_ci Some(s) => s as libc::c_int, 383da5c369Sopenharmony_ci None => 0, 393da5c369Sopenharmony_ci }; 403da5c369Sopenharmony_ci let res = unsafe { libc::pthread_kill(thread, sig) }; 413da5c369Sopenharmony_ci Errno::result(res).map(drop) 423da5c369Sopenharmony_ci} 433da5c369Sopenharmony_ci} 44