Skip to content

Commit be3773c

Browse files
committed
refactor(port_std): use #![feature(once_cell)]
`std::lazy::SyncOnceCell` was unstably added by [rust-lang/rust#72414] [1] and is being tracked by [rust-lang/rust#74465][2]. This replaces `once_cell::sync::OnceCell`. [1]: rust-lang/rust#72414 [2]: rust-lang/rust#74465
1 parent 0c670c4 commit be3773c

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/r3_port_std/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ r3_core = { version = "0.1.0", path = "../r3_core" }
1717

1818
atomic_ref = { version = "0.2.0" }
1919
env_logger = { version = "0.8.4" }
20-
once_cell = { version = "1.4.0" }
2120
spin = { version = "0.9.2", default-features = false, features = ["spin_mutex"] }
2221
slab = { version = "0.4.5" }
2322
log = { version = "0.4.8" }

src/r3_port_std/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#![feature(atomic_mut_ptr)]
33
#![feature(thread_local)]
44
#![feature(deadline_api)]
5+
#![feature(once_cell)]
56
#![cfg_attr(
67
feature = "doc",
78
doc(html_logo_url = "https://r3-os.github.io/r3/logo-small.svg")
89
)]
910
#![doc = include_str!("./lib.md")]
1011
#![deny(unsafe_op_in_unsafe_fn)]
1112
use atomic_ref::AtomicRef;
12-
use once_cell::sync::OnceCell;
1313
use r3_core::{
1414
kernel::{
1515
ClearInterruptLineError, EnableInterruptLineError, InterruptNum, InterruptPriority,
@@ -22,6 +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,
2526
sync::mpsc,
2627
time::{Duration, Instant},
2728
};
@@ -96,7 +97,7 @@ pub unsafe trait PortInstance:
9697
/// the corresponding trait methods of `Port*`.
9798
#[doc(hidden)]
9899
pub struct State {
99-
thread_group: OnceCell<ums::ThreadGroup<sched::SchedState>>,
100+
thread_group: SyncOnceCell<ums::ThreadGroup<sched::SchedState>>,
100101
timer_cmd_send: SpinMutex<Option<mpsc::Sender<TimerCmd>>>,
101102
origin: AtomicRef<'static, Instant>,
102103
}
@@ -205,7 +206,7 @@ impl TaskState {
205206
impl State {
206207
pub const fn new() -> Self {
207208
Self {
208-
thread_group: OnceCell::new(),
209+
thread_group: SyncOnceCell::new(),
209210
timer_cmd_send: SpinMutex::new(None),
210211
origin: AtomicRef::new(None),
211212
}

src/r3_port_std/src/ums.rs

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

7777
thread_local! {
78-
static TLB: OnceCell<ThreadLocalBlock> = OnceCell::new();
78+
static TLB: SyncOnceCell<ThreadLocalBlock> = SyncOnceCell::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,6 +1,6 @@
11
use super::*;
2-
use once_cell::sync::OnceCell;
32
use std::{
3+
lazy::SyncOnceCell,
44
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
55
thread::sleep,
66
time::{Duration, Instant},
@@ -21,7 +21,7 @@ fn preempt() {
2121
counters: [AtomicUsize; 3],
2222
done: AtomicBool,
2323
cur_thread: AtomicUsize,
24-
threads: OnceCell<[ThreadId; 3]>,
24+
threads: SyncOnceCell<[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: OnceCell::new(),
34+
threads: SyncOnceCell::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: OnceCell<Vec<ThreadId>>,
147+
threads: SyncOnceCell<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: OnceCell::new(),
153+
threads: SyncOnceCell::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: OnceCell<ThreadId>,
247+
threads: SyncOnceCell<ThreadId>,
248248
}
249249
let st: &_ = Box::leak(Box::new(St {
250250
done: AtomicBool::new(false),
251-
threads: OnceCell::new(),
251+
threads: SyncOnceCell::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: OnceCell<ThreadId>,
295+
threads: SyncOnceCell<ThreadId>,
296296
}
297297
let st: &_ = Box::leak(Box::new(St {
298-
threads: OnceCell::new(),
298+
threads: SyncOnceCell::new(),
299299
}));
300300

301301
impl Scheduler for &'static St {

0 commit comments

Comments
 (0)