mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Only drop OnceLock value if initialized
This commit is contained in:
@@ -48,7 +48,7 @@ mod std_oncelock {
|
|||||||
Self { value: Cell::new(core::ptr::null_mut()), init: RwLock::new(false) }
|
Self { value: Cell::new(core::ptr::null_mut()), init: RwLock::new(false) }
|
||||||
}
|
}
|
||||||
/// Shim for `std::sync::OnceLock::get_or_init`.
|
/// Shim for `std::sync::OnceLock::get_or_init`.
|
||||||
pub fn get_or_init<F>(&'a self, f: F) -> &'a T
|
pub fn get_or_init<F>(&self, f: F) -> &T
|
||||||
where
|
where
|
||||||
F: FnOnce() -> T,
|
F: FnOnce() -> T,
|
||||||
{
|
{
|
||||||
@@ -72,10 +72,12 @@ mod std_oncelock {
|
|||||||
// multiple times
|
// multiple times
|
||||||
impl<T> Drop for OnceLock<T> {
|
impl<T> Drop for OnceLock<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
if *self.init.read().unwrap() {
|
||||||
unsafe { drop(Box::from_raw(self.value.get())) }
|
unsafe { drop(Box::from_raw(self.value.get())) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#[rustversion::before(1.70)]
|
#[rustversion::before(1.70)]
|
||||||
pub use before_1_70_oncelock::OnceLock;
|
pub use before_1_70_oncelock::OnceLock;
|
||||||
#[rustversion::since(1.70)]
|
#[rustversion::since(1.70)]
|
||||||
|
|||||||
Reference in New Issue
Block a user