1 //! Unix-specific extensions to primitives in the [`std::thread`] module.
3 //! [`std::thread`]: crate::thread
5 #![stable(feature = "thread_extensions", since = "1.9.0")]
8 use crate::os::unix::raw::pthread_t;
9 use crate::sys_common::{AsInner, IntoInner};
10 use crate::thread::JoinHandle;
12 #[stable(feature = "thread_extensions", since = "1.9.0")]
14 pub type RawPthread = pthread_t;
16 /// Unix-specific extensions to [`JoinHandle`].
17 #[stable(feature = "thread_extensions", since = "1.9.0")]
18 pub trait JoinHandleExt {
19 /// Extracts the raw pthread_t without taking ownership
20 #[stable(feature = "thread_extensions", since = "1.9.0")]
21 fn as_pthread_t(&self) -> RawPthread;
23 /// Consumes the thread, returning the raw pthread_t
25 /// This function **transfers ownership** of the underlying pthread_t to
26 /// the caller. Callers are then the unique owners of the pthread_t and
27 /// must either detach or join the pthread_t once it's no longer needed.
28 #[stable(feature = "thread_extensions", since = "1.9.0")]
29 fn into_pthread_t(self) -> RawPthread;
32 #[stable(feature = "thread_extensions", since = "1.9.0")]
33 impl<T> JoinHandleExt for JoinHandle<T> {
34 fn as_pthread_t(&self) -> RawPthread {
35 self.as_inner().id() as RawPthread
38 fn into_pthread_t(self) -> RawPthread {
39 self.into_inner().into_id() as RawPthread