diff options
Diffstat (limited to 'src/liballoc/arc.rs')
| -rw-r--r-- | src/liballoc/arc.rs | 127 |
1 files changed, 50 insertions, 77 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index ccf8784e2a7..09a4f9e0a62 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -272,18 +272,6 @@ impl<T: ?Sized> Arc<T> { } } -/// Get the number of weak references to this value. -#[inline] -#[unstable(feature = "arc_counts")] -#[deprecated(since = "1.2.0", reason = "renamed to Arc::weak_count")] -pub fn weak_count<T: ?Sized>(this: &Arc<T>) -> usize { Arc::weak_count(this) } - -/// Get the number of strong references to this value. -#[inline] -#[unstable(feature = "arc_counts")] -#[deprecated(since = "1.2.0", reason = "renamed to Arc::strong_count")] -pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { Arc::strong_count(this) } - #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized> Clone for Arc<T> { /// Makes a clone of the `Arc<T>`. @@ -484,13 +472,6 @@ impl<T: ?Sized> Arc<T> { } } -#[inline] -#[unstable(feature = "arc_unique")] -#[deprecated(since = "1.2", reason = "use Arc::get_mut instead")] -pub fn get_mut<T: ?Sized>(this: &mut Arc<T>) -> Option<&mut T> { - Arc::get_mut(this) -} - #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized> Drop for Arc<T> { /// Drops the `Arc<T>`. @@ -860,7 +841,7 @@ mod tests { use std::sync::atomic::Ordering::{Acquire, SeqCst}; use std::thread; use std::vec::Vec; - use super::{Arc, Weak, get_mut, weak_count, strong_count}; + use super::{Arc, Weak}; use std::sync::Mutex; struct Canary(*mut atomic::AtomicUsize); @@ -898,43 +879,39 @@ mod tests { #[test] fn test_arc_get_mut() { - unsafe { - let mut x = Arc::new(3); - *get_mut(&mut x).unwrap() = 4; - assert_eq!(*x, 4); - let y = x.clone(); - assert!(get_mut(&mut x).is_none()); - drop(y); - assert!(get_mut(&mut x).is_some()); - let _w = x.downgrade(); - assert!(get_mut(&mut x).is_none()); - } + let mut x = Arc::new(3); + *Arc::get_mut(&mut x).unwrap() = 4; + assert_eq!(*x, 4); + let y = x.clone(); + assert!(Arc::get_mut(&mut x).is_none()); + drop(y); + assert!(Arc::get_mut(&mut x).is_some()); + let _w = x.downgrade(); + assert!(Arc::get_mut(&mut x).is_none()); } #[test] fn test_cowarc_clone_make_unique() { - unsafe { - let mut cow0 = Arc::new(75); - let mut cow1 = cow0.clone(); - let mut cow2 = cow1.clone(); - - assert!(75 == *Arc::make_unique(&mut cow0)); - assert!(75 == *Arc::make_unique(&mut cow1)); - assert!(75 == *Arc::make_unique(&mut cow2)); - - *Arc::make_unique(&mut cow0) += 1; - *Arc::make_unique(&mut cow1) += 2; - *Arc::make_unique(&mut cow2) += 3; - - assert!(76 == *cow0); - assert!(77 == *cow1); - assert!(78 == *cow2); - - // none should point to the same backing memory - assert!(*cow0 != *cow1); - assert!(*cow0 != *cow2); - assert!(*cow1 != *cow2); - } + let mut cow0 = Arc::new(75); + let mut cow1 = cow0.clone(); + let mut cow2 = cow1.clone(); + + assert!(75 == *Arc::make_unique(&mut cow0)); + assert!(75 == *Arc::make_unique(&mut cow1)); + assert!(75 == *Arc::make_unique(&mut cow2)); + + *Arc::make_unique(&mut cow0) += 1; + *Arc::make_unique(&mut cow1) += 2; + *Arc::make_unique(&mut cow2) += 3; + + assert!(76 == *cow0); + assert!(77 == *cow1); + assert!(78 == *cow2); + + // none should point to the same backing memory + assert!(*cow0 != *cow1); + assert!(*cow0 != *cow2); + assert!(*cow1 != *cow2); } #[test] @@ -947,9 +924,7 @@ mod tests { assert!(75 == *cow1); assert!(75 == *cow2); - unsafe { - *Arc::make_unique(&mut cow0) += 1; - } + *Arc::make_unique(&mut cow0) += 1; assert!(76 == *cow0); assert!(75 == *cow1); @@ -970,9 +945,7 @@ mod tests { assert!(75 == *cow0); assert!(75 == *cow1_weak.upgrade().unwrap()); - unsafe { - *Arc::make_unique(&mut cow0) += 1; - } + *Arc::make_unique(&mut cow0) += 1; assert!(76 == *cow0); assert!(cow1_weak.upgrade().is_none()); @@ -1028,40 +1001,40 @@ mod tests { #[test] fn test_strong_count() { let a = Arc::new(0u32); - assert!(strong_count(&a) == 1); + assert!(Arc::strong_count(&a) == 1); let w = a.downgrade(); - assert!(strong_count(&a) == 1); + assert!(Arc::strong_count(&a) == 1); let b = w.upgrade().expect(""); - assert!(strong_count(&b) == 2); - assert!(strong_count(&a) == 2); + assert!(Arc::strong_count(&b) == 2); + assert!(Arc::strong_count(&a) == 2); drop(w); drop(a); - assert!(strong_count(&b) == 1); + assert!(Arc::strong_count(&b) == 1); let c = b.clone(); - assert!(strong_count(&b) == 2); - assert!(strong_count(&c) == 2); + assert!(Arc::strong_count(&b) == 2); + assert!(Arc::strong_count(&c) == 2); } #[test] fn test_weak_count() { let a = Arc::new(0u32); - assert!(strong_count(&a) == 1); - assert!(weak_count(&a) == 0); + assert!(Arc::strong_count(&a) == 1); + assert!(Arc::weak_count(&a) == 0); let w = a.downgrade(); - assert!(strong_count(&a) == 1); - assert!(weak_count(&a) == 1); + assert!(Arc::strong_count(&a) == 1); + assert!(Arc::weak_count(&a) == 1); let x = w.clone(); - assert!(weak_count(&a) == 2); + assert!(Arc::weak_count(&a) == 2); drop(w); drop(x); - assert!(strong_count(&a) == 1); - assert!(weak_count(&a) == 0); + assert!(Arc::strong_count(&a) == 1); + assert!(Arc::weak_count(&a) == 0); let c = a.clone(); - assert!(strong_count(&a) == 2); - assert!(weak_count(&a) == 0); + assert!(Arc::strong_count(&a) == 2); + assert!(Arc::weak_count(&a) == 0); let d = c.downgrade(); - assert!(weak_count(&c) == 1); - assert!(strong_count(&c) == 2); + assert!(Arc::weak_count(&c) == 1); + assert!(Arc::strong_count(&c) == 2); drop(a); drop(c); |
