Skip to content

Commit

Permalink
Rollup merge of #76649 - nicbn:arc-spin-loop-hint, r=m-ou-se
Browse files Browse the repository at this point in the history
Add a spin loop hint for Arc::downgrade

Adds `hint::spin_loop()` to the case where `Arc::downgrade` spins.
  • Loading branch information
jonas-schievink authored Oct 24, 2020
2 parents 2e8a54a + 929f80e commit 8e75669
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
#![feature(raw_ref_op)]
#![feature(rustc_attrs)]
#![feature(receiver_trait)]
#![feature(renamed_spin_loop)]
#![feature(min_specialization)]
#![feature(slice_ptr_get)]
#![feature(slice_ptr_len)]
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use core::cmp::Ordering;
use core::convert::{From, TryFrom};
use core::fmt;
use core::hash::{Hash, Hasher};
use core::hint;
use core::intrinsics::abort;
use core::iter;
use core::marker::{PhantomData, Unpin, Unsize};
Expand Down Expand Up @@ -764,6 +765,7 @@ impl<T: ?Sized> Arc<T> {
loop {
// check if the weak counter is currently "locked"; if so, spin.
if cur == usize::MAX {
hint::spin_loop();
cur = this.inner().weak.load(Relaxed);
continue;
}
Expand Down

0 comments on commit 8e75669

Please sign in to comment.