Skip to content

Commit 8dddb22

Browse files
committed
sync::mpsc: quadratic backoff
1 parent 7b721ed commit 8dddb22

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/std/src/sync/mpmc/utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ impl Backoff {
110110
/// progress.
111111
#[inline]
112112
pub fn spin(&self) {
113-
for _ in 0..1 << self.step.get().min(SPIN_LIMIT) {
113+
let step = self.step.get().min(SPIN_LIMIT);
114+
for _ in 0..step.pow(2) {
114115
crate::hint::spin_loop();
115116
}
116117

@@ -123,7 +124,7 @@ impl Backoff {
123124
#[inline]
124125
pub fn snooze(&self) {
125126
if self.step.get() <= SPIN_LIMIT {
126-
for _ in 0..1 << self.step.get() {
127+
for _ in 0..self.step.get().pow(2) {
127128
crate::hint::spin_loop()
128129
}
129130
} else {

0 commit comments

Comments
 (0)