Skip to content

Commit a838a70

Browse files
committed
Add a spin loop hint for Arc::downgrade
1 parent 08deb86 commit a838a70

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
#![feature(raw_ref_op)]
117117
#![feature(rustc_attrs)]
118118
#![feature(receiver_trait)]
119+
#![feature(renamed_spin_loop)]
119120
#![feature(min_specialization)]
120121
#![feature(slice_ptr_get)]
121122
#![feature(slice_ptr_len)]

library/alloc/src/sync.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use core::convert::{From, TryFrom};
1111
use core::fmt;
1212
use core::hash::{Hash, Hasher};
1313
use core::intrinsics::abort;
14+
use core::hint;
1415
use core::iter;
1516
use core::marker::{PhantomData, Unpin, Unsize};
1617
use core::mem::{self, align_of_val, size_of_val};
@@ -764,6 +765,7 @@ impl<T: ?Sized> Arc<T> {
764765
loop {
765766
// check if the weak counter is currently "locked"; if so, spin.
766767
if cur == usize::MAX {
768+
hint::spin_loop();
767769
cur = this.inner().weak.load(Relaxed);
768770
continue;
769771
}

0 commit comments

Comments
 (0)