1 //! Low level threading primitives
2 
3 #[cfg(not(target_os = "redox"))]
4 use crate::errno::Errno;
5 #[cfg(not(target_os = "redox"))]
6 use crate::Result;
7 #[cfg(not(target_os = "redox"))]
8 use crate::sys::signal::Signal;
9 use libc::{self, pthread_t};
10 
11 /// Identifies an individual thread.
12 pub type Pthread = pthread_t;
13 
14 /// Obtain ID of the calling thread (see
15 /// [`pthread_self(3)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html)
16 ///
17 /// The thread ID returned by `pthread_self()` is not the same thing as
18 /// the kernel thread ID returned by a call to `gettid(2)`.
19 #[inline]
pthread_self() -> Pthread20 pub fn pthread_self() -> Pthread {
21     unsafe { libc::pthread_self() }
22 }
23 
24 /// Send a signal to a thread (see [`pthread_kill(3)`]).
25 ///
26 /// If `signal` is `None`, `pthread_kill` will only preform error checking and
27 /// won't send any signal.
28 ///
29 /// [`pthread_kill(3)`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html
30 #[cfg(not(target_os = "redox"))]
pthread_kill<T: Into<Option<Signal>>>(thread: Pthread, signal: T) -> Result<()>31 pub fn pthread_kill<T: Into<Option<Signal>>>(thread: Pthread, signal: T) -> Result<()> {
32     let sig = match signal.into() {
33         Some(s) => s as libc::c_int,
34         None => 0,
35     };
36     let res = unsafe { libc::pthread_kill(thread, sig) };
37     Errno::result(res).map(drop)
38 }
39