Skip to content

Commit d7e369e

Browse files
committed
fix(port_std): replace std::lazy::SyncOnceCell with std::sync::OnceLock
1 parent c341790 commit d7e369e

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/r3_port_std/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ use r3_kernel::{KernelTraits, Port, PortToKernel, System, TaskCb, UTicks};
2222
use spin::Mutex as SpinMutex;
2323
use std::{
2424
cell::Cell,
25-
lazy::SyncOnceCell,
26-
sync::mpsc,
25+
sync::{mpsc, OnceLock},
2726
time::{Duration, Instant},
2827
};
2928

@@ -97,7 +96,7 @@ pub unsafe trait PortInstance:
9796
/// the corresponding trait methods of `Port*`.
9897
#[doc(hidden)]
9998
pub struct State {
100-
thread_group: SyncOnceCell<ums::ThreadGroup<sched::SchedState>>,
99+
thread_group: OnceLock<ums::ThreadGroup<sched::SchedState>>,
101100
timer_cmd_send: SpinMutex<Option<mpsc::Sender<TimerCmd>>>,
102101
origin: AtomicRef<'static, Instant>,
103102
}
@@ -206,7 +205,7 @@ impl TaskState {
206205
impl State {
207206
pub const fn new() -> Self {
208207
Self {
209-
thread_group: SyncOnceCell::new(),
208+
thread_group: OnceLock::new(),
210209
timer_cmd_send: SpinMutex::new(None),
211210
origin: AtomicRef::new(None),
212211
}

src/r3_port_std/src/ums.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Utterly inefficient cross-platform preemptive user-mode scheduling
22
use slab::Slab;
33
use std::{
4-
lazy::SyncOnceCell,
54
panic::{catch_unwind, AssertUnwindSafe},
5+
sync::OnceLock,
66
sync::{mpsc, Arc},
77
thread::Result,
88
};
@@ -75,7 +75,7 @@ struct WorkerThread {
7575
}
7676

7777
thread_local! {
78-
static TLB: SyncOnceCell<ThreadLocalBlock> = SyncOnceCell::new();
78+
static TLB: OnceLock<ThreadLocalBlock> = OnceLock::new();
7979
}
8080

8181
struct ThreadLocalBlock {

src/r3_port_std/src/ums/tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use std::{
3-
lazy::SyncOnceCell,
43
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
4+
sync::OnceLock,
55
thread::sleep,
66
time::{Duration, Instant},
77
};
@@ -21,7 +21,7 @@ fn preempt() {
2121
counters: [AtomicUsize; 3],
2222
done: AtomicBool,
2323
cur_thread: AtomicUsize,
24-
threads: SyncOnceCell<[ThreadId; 3]>,
24+
threads: OnceLock<[ThreadId; 3]>,
2525
}
2626
let st: &_ = Box::leak(Box::new(St {
2727
counters: [
@@ -31,7 +31,7 @@ fn preempt() {
3131
],
3232
done: AtomicBool::new(false),
3333
cur_thread: AtomicUsize::new(0),
34-
threads: SyncOnceCell::new(),
34+
threads: OnceLock::new(),
3535
}));
3636

3737
impl Scheduler for &'static St {
@@ -144,13 +144,13 @@ fn yield_ring(count: usize) {
144144
counters: Vec<AtomicUsize>,
145145
done: AtomicBool,
146146
cur_thread: AtomicUsize,
147-
threads: SyncOnceCell<Vec<ThreadId>>,
147+
threads: OnceLock<Vec<ThreadId>>,
148148
}
149149
let st: &_ = Box::leak(Box::new(St {
150150
counters: (0..count).map(|_| AtomicUsize::new(0)).collect(),
151151
done: AtomicBool::new(false),
152152
cur_thread: AtomicUsize::new(0),
153-
threads: SyncOnceCell::new(),
153+
threads: OnceLock::new(),
154154
}));
155155

156156
const COUNTER_THREAD_ENDED: usize = usize::MAX;
@@ -244,11 +244,11 @@ fn preempt_rapid() {
244244

245245
struct St {
246246
done: AtomicBool,
247-
threads: SyncOnceCell<ThreadId>,
247+
threads: OnceLock<ThreadId>,
248248
}
249249
let st: &_ = Box::leak(Box::new(St {
250250
done: AtomicBool::new(false),
251-
threads: SyncOnceCell::new(),
251+
threads: OnceLock::new(),
252252
}));
253253

254254
impl Scheduler for &'static St {
@@ -292,10 +292,10 @@ fn forward_panic() {
292292
init_logger();
293293

294294
struct St {
295-
threads: SyncOnceCell<ThreadId>,
295+
threads: OnceLock<ThreadId>,
296296
}
297297
let st: &_ = Box::leak(Box::new(St {
298-
threads: SyncOnceCell::new(),
298+
threads: OnceLock::new(),
299299
}));
300300

301301
impl Scheduler for &'static St {

0 commit comments

Comments
 (0)