diff options
| author | Jacques-Henri Jourdan <jacques-henri.jourdan@normalesup.org> | 2017-07-18 19:31:22 +0200 |
|---|---|---|
| committer | Jacques-Henri Jourdan <jacques-henri.jourdan@normalesup.org> | 2017-07-18 19:39:30 +0200 |
| commit | 49edaf14fd1ef0c190e67998ad299db67d19b739 (patch) | |
| tree | a8ca9d9cf5e115b43f23692c7f3ecddf7006e155 /src/liballoc | |
| parent | 83c659ef655b1f740777f83eb415fd7ebe5a3fe5 (diff) | |
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.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/arc.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index d9edf50b9c8..0205f3f3553 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -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. |
