Skip to content
Permalink
Browse files

Remove unsound `conc::Atomic::get_mut` and replace it by `conc::Atomi…

…c::get_inner[_mut]`.
  • Loading branch information...
ticki committed Jun 10, 2017
1 parent 9d42c86 commit 1f5c889ad6d095dd47bdd264b1048f621735f80f
Showing with 8 additions and 18 deletions.
  1. +8 −18 conc/src/atomic.rs
@@ -30,15 +30,14 @@ impl<T> Atomic<T> {
}
}

/// Get a mutable reference to the underlying pointer.
///
/// # Safety
///
/// This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.
pub fn get_mut(&mut self) -> Option<&mut T> {
unsafe {
self.inner.get_mut().as_mut()
}
/// Get a mutable reference to the underlying `std::sync::AtomicPtr`.
pub unsafe fn get_inner(&self) {
&self.inner
}

/// Get an immutable reference to the underlying `std::sync::AtomicPtr`
pub unsafe fn get_inner_mut(&mut self) {
&mut self.inner
}

/// Load the container's current pointer.
@@ -339,24 +338,15 @@ mod tests {
let mut opt = Atomic::default();

assert!(opt.load(atomic::Ordering::Relaxed).is_none());
assert!(opt.get_mut().is_none());

assert!(opt.swap(None, atomic::Ordering::Relaxed).is_none());
assert!(opt.load(atomic::Ordering::Relaxed).is_none());
assert!(opt.get_mut().is_none());

assert!(opt.swap(Some(Box::new(42)), atomic::Ordering::Relaxed).is_none());
assert_eq!(*opt.load(atomic::Ordering::Relaxed).unwrap(), 42);
assert_eq!(*opt.get_mut().unwrap(), 42);

assert_eq!(*opt.swap(Some(Box::new(43)), atomic::Ordering::Relaxed).unwrap(), 42);
assert_eq!(*opt.load(atomic::Ordering::Relaxed).unwrap(), 43);
assert_eq!(*opt.get_mut().unwrap(), 43);

*opt.get_mut().unwrap() = 2;

assert_eq!(*opt.load(atomic::Ordering::Relaxed).unwrap(), 2);
assert_eq!(*opt.get_mut().unwrap(), 2);
}

#[test]

0 comments on commit 1f5c889

Please sign in to comment.
You can’t perform that action at this time.