busy wait for macos
This commit is contained in:
35
simu/src/wait.rs
Normal file
35
simu/src/wait.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use std::sync::atomic::AtomicU32;
|
||||||
|
|
||||||
|
#[cfg(feature = "futex")]
|
||||||
|
use wait_on_address::AtomicWait;
|
||||||
|
|
||||||
|
pub trait WaitOnAtomic {
|
||||||
|
fn wait(&self, v: u32);
|
||||||
|
fn signal(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "futex")]
|
||||||
|
impl WaitOnAtomic for AtomicU32 {
|
||||||
|
fn wait(&self, v: u32) {
|
||||||
|
<AtomicU32 as AtomicWait>::wait(self, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signal(&self) {
|
||||||
|
self.notify_one();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "futex"))]
|
||||||
|
impl WaitOnAtomic for AtomicU32 {
|
||||||
|
fn wait(&self, v: u32) {
|
||||||
|
while self.load(std::sync::atomic::Ordering::Acquire) == v {
|
||||||
|
use std::{thread::sleep, time::Duration};
|
||||||
|
|
||||||
|
sleep(Duration::from_micros(500));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signal(&self) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user