Lines Matching refs:strong
19526 //! [`Weak`] is used to break cycles. For example, a tree could have strong
19721 //! // are destroyed. There are now no strong (`Rc`) pointers to the
19776 strong: Cell<usize>,
19838 // There is an implicit weak pointer owned by all the strong
19840 // the allocation while the strong destructor is running, even
19841 // if the weak pointer is stored inside the strong one.
19843 Box::leak(box RcBox { strong: Cell::new(1), weak: Cell::new(1), value }).into(),
19876 strong: Cell::new(0),
19898 let prev_value = (*inner).strong.get();
19899 debug_assert_eq!(prev_value, 0, "No prior strong references should exist");
19900 (*inner).strong.set(1);
19903 let strong = Rc::from_inner(init_ptr);
19908 strong
19987 // There is an implicit weak pointer owned by all the strong
19989 // the allocation while the strong destructor is running, even
19990 // if the weak pointer is stored inside the strong one.
19992 Box::leak(Box::try_new(RcBox { strong: Cell::new(1), weak: Cell::new(1), value })?)
20070 /// Returns the inner value, if the `Rc` has exactly one strong reference.
20097 // the strong count, and then remove the implicit "strong weak"
20282 /// for as long there are strong counts in the `Rc`.
20390 /// Gets the number of strong (`Rc`) pointers to this allocation.
20405 this.inner().strong()
20408 /// Increments the strong reference count on the `Rc<T>` associated with the
20414 /// associated `Rc` instance must be valid (i.e. the strong count must be at
20441 /// Decrements the strong reference count on the `Rc<T>` associated with the
20447 /// associated `Rc` instance must be valid (i.e. the strong count must be at
20640 // Remove implicit strong-weak ref (no need to craft a fake
20735 ptr::write(&mut (*inner).strong, Cell::new(1));
20885 /// This will decrement the strong reference count. If the strong reference
20911 if self.inner().strong() == 0 {
20915 // remove the implicit "strong weak" pointer now that we've
20932 /// strong reference count.
21436 /// have strong [`Rc`] pointers from parent nodes to children, and `Weak`
21493 strong: &'a Cell<usize>,
21499 /// The pointer is valid only if there are some strong references. The pointer may be dangling,
21508 /// let strong = Rc::new("hello".to_owned());
21509 /// let weak = Rc::downgrade(&strong);
21511 /// assert!(ptr::eq(&*strong, weak.as_ptr()));
21512 /// // The strong here keeps it alive, so we can still access the object.
21515 /// drop(strong);
21552 /// let strong = Rc::new("hello".to_owned());
21553 /// let weak = Rc::downgrade(&strong);
21556 /// assert_eq!(1, Rc::weak_count(&strong));
21560 /// assert_eq!(0, Rc::weak_count(&strong));
21574 /// This can be used to safely get a strong reference (by calling [`upgrade`]
21585 /// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this
21595 /// let strong = Rc::new("hello".to_owned());
21597 /// let raw_1 = Rc::downgrade(&strong).into_raw();
21598 /// let raw_2 = Rc::downgrade(&strong).into_raw();
21600 /// assert_eq!(2, Rc::weak_count(&strong));
21603 /// assert_eq!(1, Rc::weak_count(&strong));
21605 /// drop(strong);
21651 /// // Destroy all strong pointers.
21660 if inner.strong() == 0 {
21668 /// Gets the number of strong (`Rc`) pointers pointing to this allocation.
21673 if let Some(inner) = self.inner() { inner.strong() } else { 0 }
21678 /// If no strong pointers remain, this will return zero.
21683 if inner.strong() > 0 {
21704 WeakInner { strong: &(*ptr).strong, weak: &(*ptr).weak }
21788 // the strong pointers have disappeared.
21862 fn strong(&self) -> usize {
21868 let strong = self.strong();
21874 if strong == 0 || strong == usize::MAX {
21877 self.strong_ref().set(strong + 1);
21882 self.strong_ref().set(self.strong() - 1);
21918 &self.strong
21930 self.strong
23382 /// strong `Arc` pointers from parent nodes to children, and [`Weak`]
23535 /// have strong [`Arc`] pointers from parent nodes to children, and `Weak`
23574 strong: atomic::AtomicUsize,
23577 // ability to upgrade weak pointers or downgrade strong ones; this is used
23601 // held by all the strong pointers (kinda), see std/rc.rs for more info
23603 strong: atomic::AtomicUsize::new(1),
23636 strong: atomic::AtomicUsize::new(0),
23654 // reference into a strong reference.
23660 // observe a non-zero strong count. Therefore we need at least "Release" ordering
23671 let prev_value = (*inner).strong.fetch_add(1, Release);
23672 debug_assert_eq!(prev_value, 0, "No prior strong references should exist");
23675 let strong = Arc::from_inner(init_ptr);
23680 strong
23768 // held by all the strong pointers (kinda), see std/rc.rs for more info
23770 strong: atomic::AtomicUsize::new(1),
23844 /// Returns the inner value, if the `Arc` has exactly one strong reference.
23866 if this.inner().strong.compare_exchange(1, 0, Relaxed, Relaxed).is_err() {
23870 acquire!(this.inner().strong);
23875 // Make a weak pointer to clean up the implicit strong-weak reference
24053 /// as long as there are strong counts in the `Arc`.
24197 /// Gets the number of strong (`Arc`) pointers to this allocation.
24202 /// Another thread can change the strong count at any time,
24220 this.inner().strong.load(SeqCst)
24223 /// Increments the strong reference count on the `Arc<T>` associated with the
24229 /// associated `Arc` instance must be valid (i.e. the strong count must be at
24258 /// Decrements the strong reference count on the `Arc<T>` associated with the
24264 /// associated `Arc` instance must be valid (i.e. the strong count must be at
24311 // Drop the weak ref collectively held by all strong references
24385 ptr::write(&mut (*inner).strong, atomic::AtomicUsize::new(1));
24525 /// strong reference count.
24549 let old_size = self.inner().strong.fetch_add(1, Relaxed);
24617 // Note that we hold both a strong reference and a weak reference.
24618 // Thus, releasing our strong reference only will not, by itself, cause
24622 // before release writes (i.e., decrements) to `strong`. Since we hold a
24625 if this.inner().strong.compare_exchange(1, 0, Acquire, Relaxed).is_err() {
24626 // Another strong pointer exists, so we must clone.
24639 // We removed the last strong ref, but there are additional weak
24645 // locked by a thread with a strong reference.
24660 // strong ref count.
24661 this.inner().strong.store(1, Release);
24754 // writes to `strong` (in particular in `Weak::upgrade`) prior to decrements
24758 // This needs to be an `Acquire` to synchronize with the decrement of the `strong`
24761 let unique = self.inner().strong.load(Acquire) == 1;
24764 // effectively preventing the above read of `strong` from happening
24778 /// This will decrement the strong reference count. If the strong reference
24806 if self.inner().strong.fetch_sub(1, Release) != 1 {
24838 acquire!(self.inner().strong);
24905 strong: &'a atomic::AtomicUsize,
24911 /// The pointer is valid only if there are some strong references. The pointer may be dangling,
24920 /// let strong = Arc::new("hello".to_owned());
24921 /// let weak = Arc::downgrade(&strong);
24923 /// assert!(ptr::eq(&*strong, weak.as_ptr()));
24924 /// // The strong here keeps it alive, so we can still access the object.
24927 /// drop(strong);
24964 /// let strong = Arc::new("hello".to_owned());
24965 /// let weak = Arc::downgrade(&strong);
24968 /// assert_eq!(1, Arc::weak_count(&strong));
24972 /// assert_eq!(0, Arc::weak_count(&strong));
24986 /// This can be used to safely get a strong reference (by calling [`upgrade`]
24997 /// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this
25006 /// let strong = Arc::new("hello".to_owned());
25008 /// let raw_1 = Arc::downgrade(&strong).into_raw();
25009 /// let raw_2 = Arc::downgrade(&strong).into_raw();
25011 /// assert_eq!(2, Arc::weak_count(&strong));
25014 /// assert_eq!(1, Arc::weak_count(&strong));
25016 /// drop(strong);
25065 /// // Destroy all strong pointers.
25073 // We use a CAS loop to increment the strong count instead of a
25082 let mut n = inner.strong.load(Relaxed);
25098 match inner.strong.compare_exchange_weak(n, n + 1, Acquire, Relaxed) {
25105 /// Gets the number of strong (`Arc`) pointers pointing to this allocation.
25110 if let Some(inner) = self.inner() { inner.strong.load(SeqCst) } else { 0 }
25117 /// strong pointers, this will return 0.
25129 let strong = inner.strong.load(SeqCst);
25130 if strong == 0 {
25133 // Since we observed that there was at least one strong pointer
25135 // reference (present whenever any strong references are alive)
25156 WeakInner { strong: &(*ptr).strong, weak: &(*ptr).weak }