Skip to content

Commit

Permalink
Implement the std::hint module (#78)
Browse files Browse the repository at this point in the history
The only thing we actually care about here is `hint::spin_loop`, which
we just treat the same way as `yield_now`.

Part of #75.
  • Loading branch information
jamesbornholt authored Aug 23, 2022
1 parent bae3598 commit 49e4fcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/hint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Shuttle's implementation of [`std::hint`].
pub use std::hint::*;

use crate::thread;

/// Emits a machine instruction to signal the processor that it is running in a busy-wait spin-loop
/// (“spin lock”).
pub fn spin_loop() {
// Probably not necessary, but let's emit it just in case
std::hint::spin_loop();

thread::yield_now();
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
//! [pct]: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/asplos277-pct.pdf
pub mod asynch;
pub mod hint;
pub mod rand;
pub mod sync;
pub mod thread;
Expand Down

0 comments on commit 49e4fcc

Please sign in to comment.