Auto merge of #92553 - m-ou-se:thread-join-simplify, r=Mark-Simulacrum
Simpilfy thread::JoinInner. `JoinInner`'s `native` field was an `Option`, but that's unnecessary. Also, thanks to `Arc::get_mut`, there's no unsafety needed in `JoinInner::join()`.
This commit is contained in:
commit
256721ee51
1 changed files with 9 additions and 9 deletions
|
@ -498,12 +498,12 @@ impl Builder {
|
||||||
// exist after the thread has terminated, which is signaled by `Thread::join`
|
// exist after the thread has terminated, which is signaled by `Thread::join`
|
||||||
// returning.
|
// returning.
|
||||||
native: unsafe {
|
native: unsafe {
|
||||||
Some(imp::Thread::new(
|
imp::Thread::new(
|
||||||
stack_size,
|
stack_size,
|
||||||
mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(
|
mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(
|
||||||
Box::new(main),
|
Box::new(main),
|
||||||
),
|
),
|
||||||
)?)
|
)?
|
||||||
},
|
},
|
||||||
thread: my_thread,
|
thread: my_thread,
|
||||||
packet: Packet(my_packet),
|
packet: Packet(my_packet),
|
||||||
|
@ -1261,15 +1261,15 @@ unsafe impl<T: Sync> Sync for Packet<T> {}
|
||||||
|
|
||||||
/// Inner representation for JoinHandle
|
/// Inner representation for JoinHandle
|
||||||
struct JoinInner<T> {
|
struct JoinInner<T> {
|
||||||
native: Option<imp::Thread>,
|
native: imp::Thread,
|
||||||
thread: Thread,
|
thread: Thread,
|
||||||
packet: Packet<T>,
|
packet: Packet<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> JoinInner<T> {
|
impl<T> JoinInner<T> {
|
||||||
fn join(&mut self) -> Result<T> {
|
fn join(mut self) -> Result<T> {
|
||||||
self.native.take().unwrap().join();
|
self.native.join();
|
||||||
unsafe { (*self.packet.0.get()).take().unwrap() }
|
Arc::get_mut(&mut self.packet.0).unwrap().get_mut().take().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1400,7 +1400,7 @@ impl<T> JoinHandle<T> {
|
||||||
/// join_handle.join().expect("Couldn't join on the associated thread");
|
/// join_handle.join().expect("Couldn't join on the associated thread");
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn join(mut self) -> Result<T> {
|
pub fn join(self) -> Result<T> {
|
||||||
self.0.join()
|
self.0.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1416,13 +1416,13 @@ impl<T> JoinHandle<T> {
|
||||||
|
|
||||||
impl<T> AsInner<imp::Thread> for JoinHandle<T> {
|
impl<T> AsInner<imp::Thread> for JoinHandle<T> {
|
||||||
fn as_inner(&self) -> &imp::Thread {
|
fn as_inner(&self) -> &imp::Thread {
|
||||||
self.0.native.as_ref().unwrap()
|
&self.0.native
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> IntoInner<imp::Thread> for JoinHandle<T> {
|
impl<T> IntoInner<imp::Thread> for JoinHandle<T> {
|
||||||
fn into_inner(self) -> imp::Thread {
|
fn into_inner(self) -> imp::Thread {
|
||||||
self.0.native.unwrap()
|
self.0.native
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue