diff options
| author | Raoul Strackx <raoul.strackx@fortanix.com> | 2024-05-29 14:19:09 +0200 |
|---|---|---|
| committer | Raoul Strackx <raoul.strackx@fortanix.com> | 2024-05-30 16:16:48 +0200 |
| commit | 7cd732f990ec341efdac53f6519a44b72e07861f (patch) | |
| tree | 902359e063d50f112fe77b3a5cb31431160e541d | |
| parent | cdc509f7c09361466d543fc8311ce7066b10cc4f (diff) | |
| download | rust-7cd732f990ec341efdac53f6519a44b72e07861f.tar.gz rust-7cd732f990ec341efdac53f6519a44b72e07861f.zip | |
Avoid `mut` and simplify initialization of `TASK_QUEUE`
| -rw-r--r-- | library/std/src/sys/pal/sgx/thread.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/library/std/src/sys/pal/sgx/thread.rs b/library/std/src/sys/pal/sgx/thread.rs index 7d271e6d2b6..d70c6e31fb7 100644 --- a/library/std/src/sys/pal/sgx/thread.rs +++ b/library/std/src/sys/pal/sgx/thread.rs @@ -15,7 +15,7 @@ pub use self::task_queue::JoinNotifier; mod task_queue { use super::wait_notify; - use crate::sync::{Mutex, MutexGuard, Once}; + use crate::sync::{Mutex, MutexGuard}; pub type JoinHandle = wait_notify::Waiter; @@ -32,6 +32,8 @@ mod task_queue { done: JoinNotifier, } + unsafe impl Send for Task {} + impl Task { pub(super) fn new(p: Box<dyn FnOnce()>) -> (Task, JoinHandle) { let (done, recv) = wait_notify::new(); @@ -46,17 +48,11 @@ mod task_queue { } #[cfg_attr(test, linkage = "available_externally")] - #[export_name = "_ZN16__rust_internals3std3sys3sgx6thread15TASK_QUEUE_INITE"] - static TASK_QUEUE_INIT: Once = Once::new(); - #[cfg_attr(test, linkage = "available_externally")] #[export_name = "_ZN16__rust_internals3std3sys3sgx6thread10TASK_QUEUEE"] - static mut TASK_QUEUE: Option<Mutex<Vec<Task>>> = None; + static TASK_QUEUE: Mutex<Vec<Task>> = Mutex::new(Vec::new()); pub(super) fn lock() -> MutexGuard<'static, Vec<Task>> { - unsafe { - TASK_QUEUE_INIT.call_once(|| TASK_QUEUE = Some(Default::default())); - TASK_QUEUE.as_ref().unwrap().lock().unwrap() - } + TASK_QUEUE.lock().unwrap() } } |
