adds unsafe thread::Builder::spawn_unchecked
function
moves code for `thread::Builder::spawn` into new public unsafe function `spawn_unchecked` and transforms `spawn` into a safe wrapper.
This commit is contained in:
parent
2d81989974
commit
fbb95689d6
1 changed files with 17 additions and 11 deletions
|
@ -386,6 +386,13 @@ impl Builder {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn spawn<F, T>(self, f: F) -> io::Result<JoinHandle<T>> where
|
pub fn spawn<F, T>(self, f: F) -> io::Result<JoinHandle<T>> where
|
||||||
F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
|
F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
|
||||||
|
{
|
||||||
|
unsafe { self.spawn_unchecked(f) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO: Doc
|
||||||
|
pub unsafe fn spawn_unchecked<'a, F, T>(self, f: F) -> io::Result<JoinHandle<T>> where
|
||||||
|
F: FnOnce() -> T, F: Send + 'a, T: Send + 'a
|
||||||
{
|
{
|
||||||
let Builder { name, stack_size } = self;
|
let Builder { name, stack_size } = self;
|
||||||
|
|
||||||
|
@ -402,16 +409,15 @@ impl Builder {
|
||||||
if let Some(name) = their_thread.cname() {
|
if let Some(name) = their_thread.cname() {
|
||||||
imp::Thread::set_name(name);
|
imp::Thread::set_name(name);
|
||||||
}
|
}
|
||||||
unsafe {
|
|
||||||
thread_info::set(imp::guard::current(), their_thread);
|
thread_info::set(imp::guard::current(), their_thread);
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace")]
|
||||||
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||||
::sys_common::backtrace::__rust_begin_short_backtrace(f)
|
::sys_common::backtrace::__rust_begin_short_backtrace(f)
|
||||||
}));
|
}));
|
||||||
#[cfg(not(feature = "backtrace"))]
|
#[cfg(not(feature = "backtrace"))]
|
||||||
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f));
|
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f));
|
||||||
*their_packet.get() = Some(try_result);
|
*their_packet.get() = Some(try_result);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(JoinHandle(JoinInner {
|
Ok(JoinHandle(JoinInner {
|
||||||
|
@ -420,7 +426,7 @@ impl Builder {
|
||||||
},
|
},
|
||||||
thread: my_thread,
|
thread: my_thread,
|
||||||
packet: Packet(my_packet),
|
packet: Packet(my_packet),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue