Skip to content

Commit

Permalink
sync::mpsc: quadratic backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Nov 10, 2022
1 parent 7b721ed commit 8dddb22
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/std/src/sync/mpmc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ impl Backoff {
/// progress.
#[inline]
pub fn spin(&self) {
for _ in 0..1 << self.step.get().min(SPIN_LIMIT) {
let step = self.step.get().min(SPIN_LIMIT);
for _ in 0..step.pow(2) {
crate::hint::spin_loop();
}

Expand All @@ -123,7 +124,7 @@ impl Backoff {
#[inline]
pub fn snooze(&self) {
if self.step.get() <= SPIN_LIMIT {
for _ in 0..1 << self.step.get() {
for _ in 0..self.step.get().pow(2) {
crate::hint::spin_loop()
}
} else {
Expand Down

0 comments on commit 8dddb22

Please sign in to comment.