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")]
|
||||
pub fn spawn<F, T>(self, f: F) -> io::Result<JoinHandle<T>> where
|
||||
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;
|
||||
|
||||
|
@ -402,16 +409,15 @@ impl Builder {
|
|||
if let Some(name) = their_thread.cname() {
|
||||
imp::Thread::set_name(name);
|
||||
}
|
||||
unsafe {
|
||||
thread_info::set(imp::guard::current(), their_thread);
|
||||
#[cfg(feature = "backtrace")]
|
||||
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
::sys_common::backtrace::__rust_begin_short_backtrace(f)
|
||||
}));
|
||||
#[cfg(not(feature = "backtrace"))]
|
||||
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f));
|
||||
*their_packet.get() = Some(try_result);
|
||||
}
|
||||
|
||||
thread_info::set(imp::guard::current(), their_thread);
|
||||
#[cfg(feature = "backtrace")]
|
||||
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
::sys_common::backtrace::__rust_begin_short_backtrace(f)
|
||||
}));
|
||||
#[cfg(not(feature = "backtrace"))]
|
||||
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f));
|
||||
*their_packet.get() = Some(try_result);
|
||||
};
|
||||
|
||||
Ok(JoinHandle(JoinInner {
|
||||
|
@ -420,7 +426,7 @@ impl Builder {
|
|||
},
|
||||
thread: my_thread,
|
||||
packet: Packet(my_packet),
|
||||
}))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue