Skip to content

Commit

Permalink
sync: use spin_loop_hint instead of yield_now in mpsc (#4037)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Aug 12, 2021
1 parent 84c4a6d commit c4e5623
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tokio/src/sync/mpsc/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::loom::cell::UnsafeCell;
use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize};
use crate::loom::thread;

use std::mem::MaybeUninit;
use std::ops;
Expand Down Expand Up @@ -344,8 +343,13 @@ impl<T> Block<T> {
Err(curr) => curr,
};

// When running outside of loom, this calls `spin_loop_hint`.
thread::yield_now();
#[cfg(all(test, loom))]
crate::loom::thread::yield_now();

// TODO: once we bump MSRV to 1.49+, use `hint::spin_loop` instead.
#[cfg(not(all(test, loom)))]
#[allow(deprecated)]
std::sync::atomic::spin_loop_hint();
}
}
}
Expand Down

0 comments on commit c4e5623

Please sign in to comment.