Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7450cf0

Browse files
authored
Rollup merge ofrust-lang#125800 - fortanix:raoul/rte-99-fix_mut_static_task_queue, r=jethrogb
Fix `mut` static task queue in SGX target[PR 125046](rust-lang#125046) prevents mutable references to statics with `#[linkage]`. Such a construct was used with the tests for the `x86_64-fortanix-unknown-sgx` target. This PR fixes this and cleans up code a bit in 5 steps. Each step passes CI:- The `mut` static is removed, and `Task` explicitly implements `Send`- Renaming of the `task_queue::lock` function- Pass function for `Thread` as `Send` to `Thread::imp` and update when `Packet<'scope, T>` implements `Sync`- Storing `Task::p` as a type that implements `Send`- Letting the compiler auto implement `Send` for `Task`cc: ``@jethrogb``
2 parents1632165 +ea7e91c commit7450cf0

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

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

Lines changed: 6 additions & 12 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
usesuper::wait_notify;
18-
usecrate::sync::{Mutex,MutexGuard,Once};
18+
usecrate::sync::{Mutex,MutexGuard};
1919

2020
pubtypeJoinHandle = wait_notify::Waiter;
2121

@@ -28,12 +28,12 @@ mod task_queue {
2828
}
2929

3030
pub(super)structTask{
31-
p:Box<dynFnOnce()>,
31+
p:Box<dynFnOnce() +Send>,
3232
done:JoinNotifier,
3333
}
3434

3535
implTask{
36-
pub(super)fnnew(p:Box<dynFnOnce()>) ->(Task,JoinHandle){
36+
pub(super)fnnew(p:Box<dynFnOnce() +Send>) ->(Task,JoinHandle){
3737
let(done, recv) = wait_notify::new();
3838
let done =JoinNotifier(Some(done));
3939
(Task{ p, done}, recv)
@@ -45,18 +45,12 @@ mod task_queue {
4545
}
4646
}
4747

48-
#[cfg_attr(test, linkage ="available_externally")]
49-
#[export_name ="_ZN16__rust_internals3std3sys3sgx6thread15TASK_QUEUE_INITE"]
50-
staticTASK_QUEUE_INIT:Once =Once::new();
5148
#[cfg_attr(test, linkage ="available_externally")]
5249
#[export_name ="_ZN16__rust_internals3std3sys3sgx6thread10TASK_QUEUEE"]
53-
staticmutTASK_QUEUE:Option<Mutex<Vec<Task>>> =None;
50+
staticTASK_QUEUE:Mutex<Vec<Task>> =Mutex::new(Vec::new());
5451

5552
pub(super)fnlock() ->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 {
10195

10296
implThread{
10397
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
104-
pubunsafefnnew(_stack:usize,p:Box<dynFnOnce()>) -> io::Result<Thread>{
98+
pubunsafefnnew(_stack:usize,p:Box<dynFnOnce() +Send>) -> io::Result<Thread>{
10599
letmut queue_lock = task_queue::lock();
106100
unsafe{ usercalls::launch_thread()?};
107101
let(task, handle) = task_queue::Task::new(p);

‎std/src/thread/mod.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ impl Builder {
561561
let main =Box::new(main);
562562
// SAFETY: dynamic size and alignment of the Box remain the same. See below for why the
563563
// lifetime change is justified.
564-
let main =unsafe{Box::from_raw(Box::into_raw(main)as*mut(dynFnOnce() +'static))};
564+
let main =
565+
unsafe{Box::from_raw(Box::into_raw(main)as*mut(dynFnOnce() +Send +'static))};
565566

566567
Ok(JoinInner{
567568
// SAFETY:
@@ -1544,7 +1545,7 @@ struct Packet<'scope, T> {
15441545
// The type `T` should already always be Send (otherwise the thread could not
15451546
// have been created) and the Packet is Sync because all access to the
15461547
// `UnsafeCell` synchronized (by the `join()` boundary), and `ScopeData` is Sync.
1547-
unsafeimpl<'scope,T:Sync>SyncforPacket<'scope,T>{}
1548+
unsafeimpl<'scope,T:Send>SyncforPacket<'scope,T>{}
15481549

15491550
impl<'scope,T>DropforPacket<'scope,T>{
15501551
fndrop(&mutself){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp