use std::hint;
use std::thread;
use std::time::Duration;
use crate::Sequence;
pub trait WaitStrategy: Copy + Send {
fn wait_for(&self, sequence: Sequence);
}
#[derive(Copy, Clone)]
pub struct BusySpin;
impl WaitStrategy for BusySpin {
#[inline]
fn wait_for(&self, _sequence: Sequence) {
}
}
#[derive(Copy, Clone)]
pub struct BusySpinWithSpinLoopHint;
impl WaitStrategy for BusySpinWithSpinLoopHint {
fn wait_for(&self, _sequence: Sequence) {
hint::spin_loop();
}
}
#[derive(Copy, Clone)]
pub struct Sleep {
duration: Duration
}
impl Sleep {
pub fn new(duration: Duration) -> Self {
Self { duration }
}
}
impl WaitStrategy for Sleep {
fn wait_for(&self, _sequence: Sequence) {
thread::sleep(self.duration);
}
}