Skip to content

Commit a214189

Browse files
committed
Add extensions for ScopedJoinHandle like for JoinHandle
1 parent 672e3aa commit a214189

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

library/std/src/os/unix/thread.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#[allow(deprecated)]
88
use crate::os::unix::raw::pthread_t;
99
use crate::sys_common::{AsInner, IntoInner};
10-
use crate::thread::JoinHandle;
10+
use crate::thread::{JoinHandle, ScopedJoinHandle};
1111

1212
#[stable(feature = "thread_extensions", since = "1.9.0")]
1313
#[allow(deprecated)]
@@ -39,3 +39,14 @@ impl<T> JoinHandleExt for JoinHandle<T> {
3939
self.into_inner().into_id() as RawPthread
4040
}
4141
}
42+
43+
#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
44+
impl<T> JoinHandleExt for ScopedJoinHandle<'_, T> {
45+
fn as_pthread_t(&self) -> RawPthread {
46+
self.as_inner().id() as RawPthread
47+
}
48+
49+
fn into_pthread_t(self) -> RawPthread {
50+
self.into_inner().into_id() as RawPthread
51+
}
52+
}

library/std/src/os/windows/io/handle.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,19 @@ impl<T> From<crate::thread::JoinHandle<T>> for OwnedHandle {
660660
join_handle.into_inner().into_handle().into_inner()
661661
}
662662
}
663+
664+
#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
665+
impl<T> AsHandle for crate::thread::ScopedJoinHandle<'_, T> {
666+
#[inline]
667+
fn as_handle(&self) -> BorrowedHandle<'_> {
668+
unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
669+
}
670+
}
671+
672+
#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
673+
impl<T> From<crate::thread::ScopedJoinHandle<'_, T>> for OwnedHandle {
674+
#[inline]
675+
fn from(join_handle: crate::thread::ScopedJoinHandle<'_, T>) -> OwnedHandle {
676+
join_handle.into_inner().into_handle().into_inner()
677+
}
678+
}

library/std/src/os/windows/thread.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,19 @@ impl<T> IntoRawHandle for thread::JoinHandle<T> {
2323
self.into_inner().into_handle().into_raw_handle() as *mut _
2424
}
2525
}
26+
27+
#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
28+
impl<T> AsRawHandle for thread::ScopedJoinHandle<'_, T> {
29+
#[inline]
30+
fn as_raw_handle(&self) -> RawHandle {
31+
self.as_inner().handle().as_raw_handle() as *mut _
32+
}
33+
}
34+
35+
#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
36+
impl<T> IntoRawHandle for thread::ScopedJoinHandle<'_, T> {
37+
#[inline]
38+
fn into_raw_handle(self) -> RawHandle {
39+
self.into_inner().into_handle().into_raw_handle() as *mut _
40+
}
41+
}

library/std/src/thread/scoped.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use super::{Builder, JoinInner, Result, Thread, current_or_unnamed};
1+
use super::{Builder, JoinInner, Result, Thread, current_or_unnamed, imp};
22
use crate::marker::PhantomData;
33
use crate::panic::{AssertUnwindSafe, catch_unwind, resume_unwind};
44
use crate::sync::Arc;
55
use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
66
use crate::{fmt, io};
7+
use crate::sys_common::{AsInner, IntoInner};
78

89
/// A scope to spawn scoped threads in.
910
///
@@ -347,3 +348,15 @@ impl<'scope, T> fmt::Debug for ScopedJoinHandle<'scope, T> {
347348
f.debug_struct("ScopedJoinHandle").finish_non_exhaustive()
348349
}
349350
}
351+
352+
impl<T> AsInner<imp::Thread> for ScopedJoinHandle<'_, T> {
353+
fn as_inner(&self) -> &imp::Thread {
354+
&self.0.native
355+
}
356+
}
357+
358+
impl<T> IntoInner<imp::Thread> for ScopedJoinHandle<'_, T> {
359+
fn into_inner(self) -> imp::Thread {
360+
self.0.native
361+
}
362+
}

0 commit comments

Comments
 (0)