diff options
| author | Ibraheem Ahmed <ibraheem@ibraheem.ca> | 2022-10-17 19:31:15 -0400 |
|---|---|---|
| committer | Ibraheem Ahmed <ibraheem@ibraheem.ca> | 2022-11-09 23:20:02 -0500 |
| commit | 8dddb2294310ad3e8ce0b2af735a702ad72a9a99 (patch) | |
| tree | 91880600b9dcb0e85eb1fb3fc090fa0f04e26297 /library/std/src/sync/mpmc | |
| parent | 7b721ed0cd91c10fcdb9a81b6007b54d2df54a3f (diff) | |
| download | rust-8dddb2294310ad3e8ce0b2af735a702ad72a9a99.tar.gz rust-8dddb2294310ad3e8ce0b2af735a702ad72a9a99.zip | |
`sync::mpsc`: quadratic backoff
Diffstat (limited to 'library/std/src/sync/mpmc')
| -rw-r--r-- | library/std/src/sync/mpmc/utils.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/library/std/src/sync/mpmc/utils.rs b/library/std/src/sync/mpmc/utils.rs index 3f0cb848cc5..85cf5dd2441 100644 --- a/library/std/src/sync/mpmc/utils.rs +++ b/library/std/src/sync/mpmc/utils.rs @@ -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(); } @@ -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 { |
