Skip to content

Commit

Permalink
refactor(port_std): use #![feature(once_cell)]
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
yvt committed Jun 18, 2022
1 parent 0c670c4 commit be3773c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/r3_port_std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ r3_core = { version = "0.1.0", path = "../r3_core" }

atomic_ref = { version = "0.2.0" }
env_logger = { version = "0.8.4" }
once_cell = { version = "1.4.0" }
spin = { version = "0.9.2", default-features = false, features = ["spin_mutex"] }
slab = { version = "0.4.5" }
log = { version = "0.4.8" }
Expand Down
7 changes: 4 additions & 3 deletions src/r3_port_std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#![feature(atomic_mut_ptr)]
#![feature(thread_local)]
#![feature(deadline_api)]
#![feature(once_cell)]
#![cfg_attr(
feature = "doc",
doc(html_logo_url = "https://r3-os.github.io/r3/logo-small.svg")
)]
#![doc = include_str!("./lib.md")]
#![deny(unsafe_op_in_unsafe_fn)]
use atomic_ref::AtomicRef;
use once_cell::sync::OnceCell;
use r3_core::{
kernel::{
ClearInterruptLineError, EnableInterruptLineError, InterruptNum, InterruptPriority,
Expand All @@ -22,6 +22,7 @@ use r3_kernel::{KernelTraits, Port, PortToKernel, System, TaskCb, UTicks};
use spin::Mutex as SpinMutex;
use std::{
cell::Cell,
lazy::SyncOnceCell,
sync::mpsc,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -96,7 +97,7 @@ pub unsafe trait PortInstance:
/// the corresponding trait methods of `Port*`.
#[doc(hidden)]
pub struct State {
thread_group: OnceCell<ums::ThreadGroup<sched::SchedState>>,
thread_group: SyncOnceCell<ums::ThreadGroup<sched::SchedState>>,
timer_cmd_send: SpinMutex<Option<mpsc::Sender<TimerCmd>>>,
origin: AtomicRef<'static, Instant>,
}
Expand Down Expand Up @@ -205,7 +206,7 @@ impl TaskState {
impl State {
pub const fn new() -> Self {
Self {
thread_group: OnceCell::new(),
thread_group: SyncOnceCell::new(),
timer_cmd_send: SpinMutex::new(None),
origin: AtomicRef::new(None),
}
Expand Down
4 changes: 2 additions & 2 deletions src/r3_port_std/src/ums.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Utterly inefficient cross-platform preemptive user-mode scheduling
use once_cell::sync::OnceCell;
use slab::Slab;
use std::{
lazy::SyncOnceCell,
panic::{catch_unwind, AssertUnwindSafe},
sync::{mpsc, Arc},
thread::Result,
Expand Down Expand Up @@ -75,7 +75,7 @@ struct WorkerThread {
}

thread_local! {
static TLB: OnceCell<ThreadLocalBlock> = OnceCell::new();
static TLB: SyncOnceCell<ThreadLocalBlock> = SyncOnceCell::new();
}

struct ThreadLocalBlock {
Expand Down
18 changes: 9 additions & 9 deletions src/r3_port_std/src/ums/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use once_cell::sync::OnceCell;
use std::{
lazy::SyncOnceCell,
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
thread::sleep,
time::{Duration, Instant},
Expand All @@ -21,7 +21,7 @@ fn preempt() {
counters: [AtomicUsize; 3],
done: AtomicBool,
cur_thread: AtomicUsize,
threads: OnceCell<[ThreadId; 3]>,
threads: SyncOnceCell<[ThreadId; 3]>,
}
let st: &_ = Box::leak(Box::new(St {
counters: [
Expand All @@ -31,7 +31,7 @@ fn preempt() {
],
done: AtomicBool::new(false),
cur_thread: AtomicUsize::new(0),
threads: OnceCell::new(),
threads: SyncOnceCell::new(),
}));

impl Scheduler for &'static St {
Expand Down Expand Up @@ -144,13 +144,13 @@ fn yield_ring(count: usize) {
counters: Vec<AtomicUsize>,
done: AtomicBool,
cur_thread: AtomicUsize,
threads: OnceCell<Vec<ThreadId>>,
threads: SyncOnceCell<Vec<ThreadId>>,
}
let st: &_ = Box::leak(Box::new(St {
counters: (0..count).map(|_| AtomicUsize::new(0)).collect(),
done: AtomicBool::new(false),
cur_thread: AtomicUsize::new(0),
threads: OnceCell::new(),
threads: SyncOnceCell::new(),
}));

const COUNTER_THREAD_ENDED: usize = usize::MAX;
Expand Down Expand Up @@ -244,11 +244,11 @@ fn preempt_rapid() {

struct St {
done: AtomicBool,
threads: OnceCell<ThreadId>,
threads: SyncOnceCell<ThreadId>,
}
let st: &_ = Box::leak(Box::new(St {
done: AtomicBool::new(false),
threads: OnceCell::new(),
threads: SyncOnceCell::new(),
}));

impl Scheduler for &'static St {
Expand Down Expand Up @@ -292,10 +292,10 @@ fn forward_panic() {
init_logger();

struct St {
threads: OnceCell<ThreadId>,
threads: SyncOnceCell<ThreadId>,
}
let st: &_ = Box::leak(Box::new(St {
threads: OnceCell::new(),
threads: SyncOnceCell::new(),
}));

impl Scheduler for &'static St {
Expand Down

0 comments on commit be3773c

Please sign in to comment.