Rollup merge of #125800 - fortanix:raoul/rte-99-fix_mut_static_task_q… · model-checking/verify-rust-std@7450cf0
@@ -15,7 +15,7 @@ pub use self::task_queue::JoinNotifier;
15151616mod task_queue {
1717use super::wait_notify;
18-use crate::sync::{Mutex, MutexGuard, Once};
18+use crate::sync::{Mutex, MutexGuard};
19192020pub type JoinHandle = wait_notify::Waiter;
2121@@ -28,12 +28,12 @@ mod task_queue {
2828}
29293030pub(super) struct Task {
31-p: Box<dyn FnOnce()>,
31+p: Box<dyn FnOnce() + Send>,
3232done: JoinNotifier,
3333}
34343535impl Task {
36-pub(super) fn new(p: Box<dyn FnOnce()>) -> (Task, JoinHandle) {
36+pub(super) fn new(p: Box<dyn FnOnce() + Send>) -> (Task, JoinHandle) {
3737let (done, recv) = wait_notify::new();
3838let done = JoinNotifier(Some(done));
3939(Task { p, done }, recv)
@@ -45,18 +45,12 @@ mod task_queue {
4545}
4646}
474748-#[cfg_attr(test, linkage = "available_externally")]
49-#[export_name = "_ZN16__rust_internals3std3sys3sgx6thread15TASK_QUEUE_INITE"]
50-static TASK_QUEUE_INIT: Once = Once::new();
5148#[cfg_attr(test, linkage = "available_externally")]
5249#[export_name = "_ZN16__rust_internals3std3sys3sgx6thread10TASK_QUEUEE"]
53-static mut TASK_QUEUE: Option<Mutex<Vec<Task>>> = None;
50+static TASK_QUEUE: Mutex<Vec<Task>> = Mutex::new(Vec::new());
54515552pub(super) fn lock() -> MutexGuard<'static, Vec<Task>> {
56-unsafe {
57-TASK_QUEUE_INIT.call_once(|| TASK_QUEUE = Some(Default::default()));
58-TASK_QUEUE.as_ref().unwrap().lock().unwrap()
59-}
53+TASK_QUEUE.lock().unwrap()
6054}
6155}
6256@@ -101,7 +95,7 @@ pub mod wait_notify {
1019510296impl Thread {
10397// unsafe: see thread::Builder::spawn_unchecked for safety requirements
104-pub unsafe fn new(_stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
98+pub unsafe fn new(_stack: usize, p: Box<dyn FnOnce() + Send>) -> io::Result<Thread> {
10599let mut queue_lock = task_queue::lock();
106100unsafe { usercalls::launch_thread()? };
107101let (task, handle) = task_queue::Task::new(p);