Skip to content

Commit df498d8

Browse files
committed
change Singleton's name to SingleUseCell
1 parent f677c78 commit df498d8

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ impl PrivilegeLevel {
118118

119119
/// A wrapper that can be used to safely create one mutable reference `&'static mut T` from a static variable.
120120
///
121-
/// `Singleton` is safe because it ensures that it only ever gives out one reference.
121+
/// `SingleUseCell` is safe because it ensures that it only ever gives out one reference.
122122
///
123-
/// ``Singleton<T>` is a safe alternative to `static mut` or a static `UnsafeCell<T>`.
123+
/// ``SingleUseCell<T>` is a safe alternative to `static mut` or a static `UnsafeCell<T>`.
124124
#[derive(Debug)]
125-
pub struct Singleton<T> {
125+
pub struct SingleUseCell<T> {
126126
used: AtomicBool,
127127
value: UnsafeCell<T>,
128128
}
129129

130-
impl<T> Singleton<T> {
131-
/// Construct a new singleton.
130+
impl<T> SingleUseCell<T> {
131+
/// Construct a new SingleUseCell.
132132
pub const fn new(value: T) -> Self {
133133
Self {
134134
used: AtomicBool::new(false),
@@ -141,9 +141,9 @@ impl<T> Singleton<T> {
141141
/// called and fail on all following calls.
142142
///
143143
/// ```
144-
/// use x86_64::Singleton;
144+
/// use x86_64::SingleUseCell;
145145
///
146-
/// static FOO: Singleton<i32> = Singleton::new(0);
146+
/// static FOO: SingleUseCell<i32> = SingleUseCell::new(0);
147147
///
148148
/// // Call `try_get_mut` for the first time and get a reference.
149149
/// let first: &'static mut i32 = FOO.try_get_mut().unwrap();
@@ -165,9 +165,9 @@ impl<T> Singleton<T> {
165165
}
166166
}
167167

168-
// SAFETY: Sharing a `Singleton<T>` between threads is safe regardless of whether `T` is `Sync`
168+
// SAFETY: Sharing a `SingleUseCell<T>` between threads is safe regardless of whether `T` is `Sync`
169169
// because we only expose the inner value once to one thread.
170-
unsafe impl<T> Sync for Singleton<T> {}
170+
unsafe impl<T> Sync for SingleUseCell<T> {}
171171

172-
// SAFETY: It's safe to send a `Singleton<T>` to another thread if it's safe to send `T`.
173-
unsafe impl<T: Send> Send for Singleton<T> {}
172+
// SAFETY: It's safe to send a `SingleUseCell<T>` to another thread if it's safe to send `T`.
173+
unsafe impl<T: Send> Send for SingleUseCell<T> {}

testing/src/gdt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lazy_static::lazy_static;
22
use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector};
33
use x86_64::structures::tss::TaskStateSegment;
4-
use x86_64::{Singleton, VirtAddr};
4+
use x86_64::{SingleUseCell, VirtAddr};
55

66
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;
77

@@ -18,12 +18,12 @@ lazy_static! {
1818
};
1919
tss
2020
};
21-
static ref GDT: (Singleton<GlobalDescriptorTable>, Selectors) = {
21+
static ref GDT: (SingleUseCell<GlobalDescriptorTable>, Selectors) = {
2222
let mut gdt = GlobalDescriptorTable::new();
2323
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
2424
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
2525
(
26-
Singleton::new(gdt),
26+
SingleUseCell::new(gdt),
2727
Selectors {
2828
code_selector,
2929
tss_selector,
@@ -38,7 +38,7 @@ struct Selectors {
3838
}
3939

4040
pub fn init() {
41-
use x86_64::instructions::segmentation::{CS, Segment};
41+
use x86_64::instructions::segmentation::{Segment, CS};
4242
use x86_64::instructions::tables::load_tss;
4343

4444
GDT.0.try_get_mut().unwrap().load();

0 commit comments

Comments
 (0)