Skip to content

Commit

Permalink
chore: remove unused barging related code
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromfedricci committed Jan 8, 2025
1 parent 5d3dae6 commit a028d47
Showing 1 changed file with 0 additions and 88 deletions.
88 changes: 0 additions & 88 deletions src/loom.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,3 @@
#[cfg(feature = "barging")]
pub use guard::{Guard, GuardDeref, GuardDerefMut};

#[cfg(feature = "barging")]
mod guard {
use core::marker::PhantomData;
use core::ops::{Deref, DerefMut};

use loom::cell::{ConstPtr, MutPtr, UnsafeCell};

/// A trait for guard types that protect the access to the underlying data
/// behind Loom's [`UnsafeCell`].
///
/// # Safety
///
/// Must guarantee that an instance of the guard is the only access point
/// to the underlying data through all its lifetime.
pub unsafe trait Guard: Sized {
/// The target type after dereferencing [`GuardDeref`] or [`GuardDerefMut`].
type Target: ?Sized;

/// Returns a shared reference to the underlying [`UnsafeCell`].
fn get(&self) -> &UnsafeCell<Self::Target>;

/// Get a Loom immutable pointer bounded by this guard lifetime.
fn get_ref(&self) -> GuardDeref<'_, Self> {
GuardDeref::new(self)
}

/// Get a Loom mutable pointer bounded by this guard lifetime.
fn get_mut(&mut self) -> GuardDerefMut<'_, Self> {
GuardDerefMut::new(self)
}
}

/// A Loom immutable pointer borrowed from a guard instance.
pub struct GuardDeref<'a, G: Guard> {
ptr: ConstPtr<G::Target>,
marker: PhantomData<(&'a G::Target, &'a G)>,
}

impl<G: Guard> GuardDeref<'_, G> {
fn new(guard: &G) -> Self {
let ptr = guard.get().get();
Self { ptr, marker: PhantomData }
}
}

impl<G: Guard> Deref for GuardDeref<'_, G> {
type Target = G::Target;

fn deref(&self) -> &Self::Target {
// SAFETY: Our lifetime is bounded by the guard borrow.
unsafe { self.ptr.deref() }
}
}

/// A Loom mutable pointer borrowed from a guard instance.
pub struct GuardDerefMut<'a, G: Guard> {
ptr: MutPtr<G::Target>,
marker: PhantomData<(&'a mut G::Target, &'a mut G)>,
}

impl<G: Guard> GuardDerefMut<'_, G> {
#[allow(clippy::needless_pass_by_ref_mut)]
fn new(guard: &mut G) -> Self {
let ptr = guard.get().get_mut();
Self { ptr, marker: PhantomData }
}
}

impl<G: Guard> Deref for GuardDerefMut<'_, G> {
type Target = G::Target;

fn deref(&self) -> &Self::Target {
// SAFETY: Our lifetime is bounded by the guard borrow.
unsafe { self.ptr.deref() }
}
}

impl<G: Guard> DerefMut for GuardDerefMut<'_, G> {
fn deref_mut(&mut self) -> &mut Self::Target {
// SAFETY: Our lifetime is bounded by the guard borrow.
unsafe { self.ptr.deref() }
}
}
}

pub mod models {
use core::array;

Expand Down

0 comments on commit a028d47

Please sign in to comment.