Fix in weak_count in Arc.
In the case the weak count was locked, the weak_count function could return usize::MAX. We need to test this condition manually.
This commit is contained in:
parent
83c659ef65
commit
49edaf14fd
@ -453,7 +453,10 @@ impl<T: ?Sized> Arc<T> {
|
||||
#[inline]
|
||||
#[stable(feature = "arc_counts", since = "1.15.0")]
|
||||
pub fn weak_count(this: &Self) -> usize {
|
||||
this.inner().weak.load(SeqCst) - 1
|
||||
let cnt = this.inner().weak.load(SeqCst);
|
||||
// If the weak count is currently locked, the value of the
|
||||
// count was 0 just before taking the lock.
|
||||
if cnt == usize::MAX { 0 } else { cnt - 1 }
|
||||
}
|
||||
|
||||
/// Gets the number of strong (`Arc`) pointers to this value.
|
||||
|
Loading…
Reference in New Issue
Block a user