1//! Unix-specific extensions to primitives in the [`std::thread`] module.
2//!
3//! [`std::thread`]: crate::thread
45#![stable(feature = "thread_extensions", since = "1.9.0")]
67#[allow(deprecated)]
8use crate::os::unix::raw::pthread_t;
9use crate::sys_common::{AsInner, IntoInner};
10use crate::thread::JoinHandle;
1112#[stable(feature = "thread_extensions", since = "1.9.0")]
13#[allow(deprecated)]
14pub type RawPthread = pthread_t;
1516/// Unix-specific extensions to [`JoinHandle`].
17#[stable(feature = "thread_extensions", since = "1.9.0")]
18pub trait JoinHandleExt {
19/// Extracts the raw pthread_t without taking ownership
20#[stable(feature = "thread_extensions", since = "1.9.0")]
21fn as_pthread_t(&self) -> RawPthread;
2223/// Consumes the thread, returning the raw pthread_t
24 ///
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")]
29fn into_pthread_t(self) -> RawPthread;
30}
3132#[stable(feature = "thread_extensions", since = "1.9.0")]
33impl<T> JoinHandleExt for JoinHandle<T> {
34fn as_pthread_t(&self) -> RawPthread {
35self.as_inner().id() as RawPthread
36 }
3738fn into_pthread_t(self) -> RawPthread {
39self.into_inner().into_id() as RawPthread
40 }
41}