busy wait for macos
This commit is contained in:
@@ -8,11 +8,13 @@ pixels = "0.15.0"
|
|||||||
winit = { version = "0.30.13", features = ["x11", "x11-dl", "x11rb", "ahash", "bytemuck", "memmap2", "rwh_06", "sctk", "sctk-adwaita"] }
|
winit = { version = "0.30.13", features = ["x11", "x11-dl", "x11rb", "ahash", "bytemuck", "memmap2", "rwh_06", "sctk", "sctk-adwaita"] }
|
||||||
winit_input_helper = "0.17.0"
|
winit_input_helper = "0.17.0"
|
||||||
parse_int = { version = "0.9.0", optional = true }
|
parse_int = { version = "0.9.0", optional = true }
|
||||||
wait_on_address = "0.1.4"
|
wait_on_address = { version = "0.1.4", optional = true }
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["futex"]
|
||||||
div_mul = []
|
div_mul = []
|
||||||
rgba = []
|
rgba = []
|
||||||
rich_keyboard = []
|
rich_keyboard = []
|
||||||
debug = ["dep:parse_int"]
|
debug = ["dep:parse_int"]
|
||||||
|
futex = ["dep:wait_on_address"]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::wait::WaitOnAtomic;
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::{
|
use std::{
|
||||||
@@ -9,7 +10,6 @@ use std::{
|
|||||||
sync::atomic::AtomicU32,
|
sync::atomic::AtomicU32,
|
||||||
time::{self, Instant},
|
time::{self, Instant},
|
||||||
};
|
};
|
||||||
use wait_on_address::AtomicWait;
|
|
||||||
pub(crate) struct SharedState {
|
pub(crate) struct SharedState {
|
||||||
pub(crate) keyboard: [AtomicU32; 4],
|
pub(crate) keyboard: [AtomicU32; 4],
|
||||||
pub(crate) screen_buf: [AtomicU32; 480 * 640],
|
pub(crate) screen_buf: [AtomicU32; 480 * 640],
|
||||||
@@ -643,7 +643,7 @@ impl Computer {
|
|||||||
InteruptKind::MMIO => {
|
InteruptKind::MMIO => {
|
||||||
(&SHARED.external_interupts)
|
(&SHARED.external_interupts)
|
||||||
.store(0, std::sync::atomic::Ordering::Release);
|
.store(0, std::sync::atomic::Ordering::Release);
|
||||||
SHARED.external_interupts.notify_one();
|
SHARED.external_interupts.signal();
|
||||||
//no need to check prev because MMIO is the lowest priority
|
//no need to check prev because MMIO is the lowest priority
|
||||||
self.interupts = InteruptState::Enabled
|
self.interupts = InteruptState::Enabled
|
||||||
}
|
}
|
||||||
@@ -688,7 +688,7 @@ impl Computer {
|
|||||||
(&SHARED.external_enabled_interupts)
|
(&SHARED.external_enabled_interupts)
|
||||||
.store(0, std::sync::atomic::Ordering::Relaxed);
|
.store(0, std::sync::atomic::Ordering::Relaxed);
|
||||||
(&SHARED.external_interupts).store(0, std::sync::atomic::Ordering::Relaxed);
|
(&SHARED.external_interupts).store(0, std::sync::atomic::Ordering::Relaxed);
|
||||||
SHARED.external_interupts.notify_all();
|
SHARED.external_interupts.signal();
|
||||||
}
|
}
|
||||||
Instruction::Swi() => {
|
Instruction::Swi() => {
|
||||||
self.pc += 1;
|
self.pc += 1;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ use std::thread::scope;
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use pixels::{Error, Pixels, SurfaceTexture};
|
use pixels::{Error, Pixels, SurfaceTexture};
|
||||||
use wait_on_address::AtomicWait;
|
|
||||||
use winit::application::ApplicationHandler;
|
use winit::application::ApplicationHandler;
|
||||||
use winit::dpi::LogicalSize;
|
use winit::dpi::LogicalSize;
|
||||||
use winit::event::WindowEvent;
|
use winit::event::WindowEvent;
|
||||||
@@ -27,6 +26,8 @@ use winit::window::Window;
|
|||||||
// use winit_input_helper::WinitInputHelper;
|
// use winit_input_helper::WinitInputHelper;
|
||||||
|
|
||||||
use crate::cpu::{Computer, MMIOInterupt};
|
use crate::cpu::{Computer, MMIOInterupt};
|
||||||
|
mod wait;
|
||||||
|
use wait::WaitOnAtomic;
|
||||||
mod cpu;
|
mod cpu;
|
||||||
use cpu::SHARED;
|
use cpu::SHARED;
|
||||||
|
|
||||||
@@ -121,7 +122,7 @@ impl<'a> ApplicationHandler for App<'a> {
|
|||||||
(&SHARED.external_interupts).store(MMIOInterupt::Keyboard.into(), Release);
|
(&SHARED.external_interupts).store(MMIOInterupt::Keyboard.into(), Release);
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
println!("wake due to keyboard event");
|
println!("wake due to keyboard event");
|
||||||
SHARED.external_interupts.notify_one();
|
SHARED.external_interupts.signal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
@@ -150,7 +151,7 @@ impl<'a> ApplicationHandler for App<'a> {
|
|||||||
(&SHARED.external_interupts).store(MMIOInterupt::MouseMove.into(), Release);
|
(&SHARED.external_interupts).store(MMIOInterupt::MouseMove.into(), Release);
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
println!("wake due mouse move");
|
println!("wake due mouse move");
|
||||||
SHARED.external_interupts.notify_one();
|
SHARED.external_interupts.signal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// WindowEvent::MouseWheel {
|
// WindowEvent::MouseWheel {
|
||||||
@@ -184,7 +185,7 @@ impl<'a> ApplicationHandler for App<'a> {
|
|||||||
(&SHARED.external_interupts).store(MMIOInterupt::MouseClick.into(), Release);
|
(&SHARED.external_interupts).store(MMIOInterupt::MouseClick.into(), Release);
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
println!("wake mouse click");
|
println!("wake mouse click");
|
||||||
SHARED.external_interupts.notify_one();
|
SHARED.external_interupts.signal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::ScaleFactorChanged { .. } => {
|
WindowEvent::ScaleFactorChanged { .. } => {
|
||||||
@@ -197,7 +198,7 @@ impl<'a> ApplicationHandler for App<'a> {
|
|||||||
!= 0;
|
!= 0;
|
||||||
if enabled {
|
if enabled {
|
||||||
(&SHARED.external_interupts).store(MMIOInterupt::VSync.into(), Relaxed);
|
(&SHARED.external_interupts).store(MMIOInterupt::VSync.into(), Relaxed);
|
||||||
SHARED.external_interupts.notify_one();
|
SHARED.external_interupts.signal();
|
||||||
wait_int();
|
wait_int();
|
||||||
}
|
}
|
||||||
let pix = self.pixels.as_mut().unwrap();
|
let pix = self.pixels.as_mut().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user