diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-07-04 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-07-04 11:40:27 +0200 |
| commit | 8900502a887d98a8f5a6b8774f1c756e89d4c29f (patch) | |
| tree | 26f0a63bf75ab8914f48e718c8cbab58f4cf07e7 /src/liballoc | |
| parent | dbf3ae7c3beb5b493375bf76152e490b8cc81d1c (diff) | |
Remove unnecessary release from Arc::try_unwrap
The thread that recovers the unique access to Arc inner value (e.g., drop when ref-count strong reaches zero, successful try_unwrap), ensures that other operations on Arc inner value happened before by synchronizing with release operations performed when decrementing the reference counter. When try_unwrap succeeds, the current thread recovers the unique access to Arc inner value, so release is unnecessary.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/sync.rs | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index ac3ce2255c8..2d6a3917c76 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -419,8 +419,7 @@ impl<T> Arc<T> { #[inline] #[stable(feature = "arc_unique", since = "1.4.0")] pub fn try_unwrap(this: Self) -> Result<T, Self> { - // See `drop` for why all these atomics are like this - if this.inner().strong.compare_exchange(1, 0, Release, Relaxed).is_err() { + if this.inner().strong.compare_exchange(1, 0, Relaxed, Relaxed).is_err() { return Err(this); } |
