Skip to content

Commit b2fadb8

Browse files
committed
Remove SignleUseCell
It's no longer used, so we don't need it anymore. Signed-off-by: Joe Richey <[email protected]>
1 parent 055d014 commit b2fadb8

File tree

2 files changed

+4
-64
lines changed

2 files changed

+4
-64
lines changed

src/lib.rs

-60
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#![deny(missing_debug_implementations)]
1212
#![deny(unsafe_op_in_unsafe_fn)]
1313

14-
use core::cell::UnsafeCell;
15-
use core::sync::atomic::{AtomicBool, Ordering};
16-
1714
pub use crate::addr::{align_down, align_up, PhysAddr, VirtAddr};
1815

1916
pub mod addr;
@@ -66,60 +63,3 @@ impl PrivilegeLevel {
6663
}
6764
}
6865
}
69-
70-
/// A wrapper that can be used to safely create one mutable reference `&'static mut T` from a static variable.
71-
///
72-
/// `SingleUseCell` is safe because it ensures that it only ever gives out one reference.
73-
///
74-
/// ``SingleUseCell<T>` is a safe alternative to `static mut` or a static `UnsafeCell<T>`.
75-
#[derive(Debug)]
76-
pub struct SingleUseCell<T> {
77-
used: AtomicBool,
78-
value: UnsafeCell<T>,
79-
}
80-
81-
impl<T> SingleUseCell<T> {
82-
/// Construct a new SingleUseCell.
83-
pub const fn new(value: T) -> Self {
84-
Self {
85-
used: AtomicBool::new(false),
86-
value: UnsafeCell::new(value),
87-
}
88-
}
89-
90-
/// Try to acquire a mutable reference to the wrapped value.
91-
/// This will only succeed the first time the function is
92-
/// called and fail on all following calls.
93-
///
94-
/// ```
95-
/// use x86_64::SingleUseCell;
96-
///
97-
/// static FOO: SingleUseCell<i32> = SingleUseCell::new(0);
98-
///
99-
/// // Call `try_get_mut` for the first time and get a reference.
100-
/// let first: &'static mut i32 = FOO.try_get_mut().unwrap();
101-
/// assert_eq!(first, &0);
102-
///
103-
/// // Calling `try_get_mut` again will return `None`.
104-
/// assert_eq!(FOO.try_get_mut(), None);
105-
/// ```
106-
pub fn try_get_mut(&self) -> Option<&mut T> {
107-
let already_used = self.used.swap(true, Ordering::AcqRel);
108-
if already_used {
109-
None
110-
} else {
111-
Some(unsafe {
112-
// SAFETY: no reference has been given out yet and we won't give out another.
113-
&mut *self.value.get()
114-
})
115-
}
116-
}
117-
}
118-
119-
// SAFETY: Sharing a `SingleUseCell<T>` between threads is safe regardless of whether `T` is `Sync`
120-
// because we only expose the inner value once to one thread. The `T: Send` bound makes sure that
121-
// sending a unique reference to another thread is safe.
122-
unsafe impl<T: Send> Sync for SingleUseCell<T> {}
123-
124-
// SAFETY: It's safe to send a `SingleUseCell<T>` to another thread if it's safe to send `T`.
125-
unsafe impl<T: Send> Send for SingleUseCell<T> {}

testing/src/gdt.rs

+4-4
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::{SingleUseCell, VirtAddr};
4+
use x86_64::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: (SingleUseCell<GlobalDescriptorTable>, Selectors) = {
21+
static ref GDT: (GlobalDescriptorTable, Selectors) = {
2222
let mut gdt = GlobalDescriptorTable::new();
2323
let code_selector = gdt.append(Descriptor::kernel_code_segment());
2424
let tss_selector = gdt.append(Descriptor::tss_segment(&TSS));
2525
(
26-
SingleUseCell::new(gdt),
26+
gdt,
2727
Selectors {
2828
code_selector,
2929
tss_selector,
@@ -41,7 +41,7 @@ pub fn init() {
4141
use x86_64::instructions::segmentation::{Segment, CS};
4242
use x86_64::instructions::tables::load_tss;
4343

44-
GDT.0.try_get_mut().unwrap().load();
44+
GDT.0.load();
4545
unsafe {
4646
CS::set_reg(GDT.1.code_selector);
4747
load_tss(GDT.1.tss_selector);

0 commit comments

Comments
 (0)