Rollup merge of #59818 - crlf0710:eliminate_libstd_fnbox, r=cramertj
Eliminate `FnBox` usages from libstd.
This commit is contained in:
commit
8ad17ec6e4
10 changed files with 15 additions and 24 deletions
|
|
@ -1,4 +1,3 @@
|
|||
use crate::boxed::FnBox;
|
||||
use crate::cmp;
|
||||
use crate::ffi::CStr;
|
||||
use crate::io;
|
||||
|
|
@ -22,7 +21,7 @@ unsafe impl Sync for Thread {}
|
|||
|
||||
impl Thread {
|
||||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||
pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>) -> io::Result<Thread> {
|
||||
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||
let p = box p;
|
||||
let mut native: libc::pthread_t = mem::zeroed();
|
||||
let mut attr: libc::pthread_attr_t = mem::zeroed();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use crate::boxed::FnBox;
|
||||
use crate::ffi::CStr;
|
||||
use crate::io;
|
||||
use crate::mem;
|
||||
|
|
@ -19,7 +18,7 @@ unsafe impl Sync for Thread {}
|
|||
|
||||
impl Thread {
|
||||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||
pub unsafe fn new(_stack: usize, p: Box<dyn FnBox()>) -> io::Result<Thread> {
|
||||
pub unsafe fn new(_stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||
let p = box p;
|
||||
|
||||
let id = cvt(syscall::clone(syscall::CLONE_VM | syscall::CLONE_FS | syscall::CLONE_FILES))?;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#![cfg_attr(test, allow(dead_code))] // why is this necessary?
|
||||
use crate::boxed::FnBox;
|
||||
use crate::ffi::CStr;
|
||||
use crate::io;
|
||||
use crate::time::Duration;
|
||||
|
|
@ -13,17 +12,16 @@ pub const DEFAULT_MIN_STACK_SIZE: usize = 4096;
|
|||
mod task_queue {
|
||||
use crate::sync::{Mutex, MutexGuard, Once};
|
||||
use crate::sync::mpsc;
|
||||
use crate::boxed::FnBox;
|
||||
|
||||
pub type JoinHandle = mpsc::Receiver<()>;
|
||||
|
||||
pub(super) struct Task {
|
||||
p: Box<dyn FnBox()>,
|
||||
p: Box<dyn FnOnce()>,
|
||||
done: mpsc::Sender<()>,
|
||||
}
|
||||
|
||||
impl Task {
|
||||
pub(super) fn new(p: Box<dyn FnBox()>) -> (Task, JoinHandle) {
|
||||
pub(super) fn new(p: Box<dyn FnOnce()>) -> (Task, JoinHandle) {
|
||||
let (done, recv) = mpsc::channel();
|
||||
(Task { p, done }, recv)
|
||||
}
|
||||
|
|
@ -51,7 +49,7 @@ mod task_queue {
|
|||
|
||||
impl Thread {
|
||||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||
pub unsafe fn new(_stack: usize, p: Box<dyn FnBox()>)
|
||||
pub unsafe fn new(_stack: usize, p: Box<dyn FnOnce()>)
|
||||
-> io::Result<Thread>
|
||||
{
|
||||
let mut queue_lock = task_queue::lock();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use crate::boxed::FnBox;
|
||||
use crate::cmp;
|
||||
use crate::ffi::CStr;
|
||||
use crate::io;
|
||||
|
|
@ -39,7 +38,7 @@ unsafe fn pthread_attr_setstacksize(_attr: *mut libc::pthread_attr_t,
|
|||
|
||||
impl Thread {
|
||||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||
pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>)
|
||||
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>)
|
||||
-> io::Result<Thread> {
|
||||
let p = box p;
|
||||
let mut native: libc::pthread_t = mem::zeroed();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use crate::boxed::FnBox;
|
||||
use crate::cmp;
|
||||
use crate::ffi::CStr;
|
||||
use crate::io;
|
||||
|
|
@ -13,7 +12,7 @@ pub const DEFAULT_MIN_STACK_SIZE: usize = 4096;
|
|||
|
||||
impl Thread {
|
||||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||
pub unsafe fn new(_stack: usize, _p: Box<dyn FnBox()>)
|
||||
pub unsafe fn new(_stack: usize, _p: Box<dyn FnOnce()>)
|
||||
-> io::Result<Thread>
|
||||
{
|
||||
unsupported()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use crate::boxed::FnBox;
|
||||
use crate::ffi::CStr;
|
||||
use crate::io;
|
||||
use crate::sys::{unsupported, Void};
|
||||
|
|
@ -10,7 +9,7 @@ pub const DEFAULT_MIN_STACK_SIZE: usize = 4096;
|
|||
|
||||
impl Thread {
|
||||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||
pub unsafe fn new(_stack: usize, _p: Box<dyn FnBox()>)
|
||||
pub unsafe fn new(_stack: usize, _p: Box<dyn FnOnce()>)
|
||||
-> io::Result<Thread>
|
||||
{
|
||||
unsupported()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use crate::boxed::FnBox;
|
||||
use crate::io;
|
||||
use crate::ffi::CStr;
|
||||
use crate::mem;
|
||||
|
|
@ -20,7 +19,7 @@ pub struct Thread {
|
|||
|
||||
impl Thread {
|
||||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
|
||||
pub unsafe fn new(stack: usize, p: Box<dyn FnBox()>)
|
||||
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>)
|
||||
-> io::Result<Thread> {
|
||||
let p = box p;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@
|
|||
//!
|
||||
//! Documentation can be found on the `rt::at_exit` function.
|
||||
|
||||
use crate::boxed::FnBox;
|
||||
use crate::ptr;
|
||||
use crate::mem;
|
||||
use crate::sys_common::mutex::Mutex;
|
||||
|
||||
type Queue = Vec<Box<dyn FnBox()>>;
|
||||
type Queue = Vec<Box<dyn FnOnce()>>;
|
||||
|
||||
// NB these are specifically not types from `std::sync` as they currently rely
|
||||
// on poisoning and this module needs to operate at a lower level than requiring
|
||||
|
|
@ -61,7 +60,7 @@ pub fn cleanup() {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn push(f: Box<dyn FnBox()>) -> bool {
|
||||
pub fn push(f: Box<dyn FnOnce()>) -> bool {
|
||||
unsafe {
|
||||
let _guard = LOCK.lock();
|
||||
if init() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use crate::boxed::FnBox;
|
||||
use crate::env;
|
||||
use crate::sync::atomic::{self, Ordering};
|
||||
use crate::sys::stack_overflow;
|
||||
|
|
@ -11,7 +10,7 @@ pub unsafe fn start_thread(main: *mut u8) {
|
|||
let _handler = stack_overflow::Handler::new();
|
||||
|
||||
// Finally, let's run some code.
|
||||
Box::from_raw(main as *mut Box<dyn FnBox()>)()
|
||||
Box::from_raw(main as *mut Box<dyn FnOnce()>)()
|
||||
}
|
||||
|
||||
pub fn min_stack() -> usize {
|
||||
|
|
|
|||
|
|
@ -157,7 +157,6 @@
|
|||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use crate::any::Any;
|
||||
use crate::boxed::FnBox;
|
||||
use crate::cell::UnsafeCell;
|
||||
use crate::ffi::{CStr, CString};
|
||||
use crate::fmt;
|
||||
|
|
@ -488,7 +487,9 @@ impl Builder {
|
|||
// returning.
|
||||
native: Some(imp::Thread::new(
|
||||
stack_size,
|
||||
mem::transmute::<Box<dyn FnBox() + 'a>, Box<dyn FnBox() + 'static>>(Box::new(main))
|
||||
mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(Box::new(
|
||||
main,
|
||||
)),
|
||||
)?),
|
||||
thread: my_thread,
|
||||
packet: Packet(my_packet),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue