1//! Unix-specific extensions to primitives in the [`std::thread`] module.
2//!
3//! [`std::thread`]: crate::thread
4
5#![stable(feature = "thread_extensions", since = "1.9.0")]
6
7#[allow(deprecated)]
8use crate::os::unix::raw::pthread_t;
9use crate::sys_common::{AsInner, IntoInner};
10use crate::thread::JoinHandle;
11
12#[stable(feature = "thread_extensions", since = "1.9.0")]
13#[allow(deprecated)]
14pub type RawPthread = pthread_t;
15
16/// 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")]
21 fn as_pthread_t(&self) -> RawPthread;
22
23 /// 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")]
29 fn into_pthread_t(self) -> RawPthread;
30}
31
32#[stable(feature = "thread_extensions", since = "1.9.0")]
33impl<T> JoinHandleExt for JoinHandle<T> {
34 fn as_pthread_t(&self) -> RawPthread {
35 self.as_inner().id() as RawPthread
36 }
37
38 fn into_pthread_t(self) -> RawPthread {
39 self.into_inner().into_id() as RawPthread
40 }
41}
42