Skip to content

Commit 8943103

Browse files
committed
Avoid mut and simplify initialization of TASK_QUEUE
1 parent a74509c commit 8943103

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

std/src/sys/pal/sgx/thread.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::task_queue::JoinNotifier;
1515

1616
mod task_queue {
1717
use super::wait_notify;
18-
use crate::sync::{Mutex, MutexGuard, Once};
18+
use crate::sync::{Mutex, MutexGuard};
1919

2020
pub type JoinHandle = wait_notify::Waiter;
2121

@@ -32,6 +32,8 @@ mod task_queue {
3232
done: JoinNotifier,
3333
}
3434

35+
unsafe impl Send for Task {}
36+
3537
impl Task {
3638
pub(super) fn new(p: Box<dyn FnOnce()>) -> (Task, JoinHandle) {
3739
let (done, recv) = wait_notify::new();
@@ -45,18 +47,12 @@ mod task_queue {
4547
}
4648
}
4749

48-
#[cfg_attr(test, linkage = "available_externally")]
49-
#[export_name = "_ZN16__rust_internals3std3sys3sgx6thread15TASK_QUEUE_INITE"]
50-
static TASK_QUEUE_INIT: Once = Once::new();
5150
#[cfg_attr(test, linkage = "available_externally")]
5251
#[export_name = "_ZN16__rust_internals3std3sys3sgx6thread10TASK_QUEUEE"]
53-
static mut TASK_QUEUE: Option<Mutex<Vec<Task>>> = None;
52+
static TASK_QUEUE: Mutex<Vec<Task>> = Mutex::new(Vec::new());
5453

5554
pub(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-
}
55+
TASK_QUEUE.lock().unwrap()
6056
}
6157
}
6258

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy