Fix PIT Interrupt Not Context Switching [irq]
PIT interrupt should context switch or else all of redox crashes.
This will fix programs like the Snake game crashing all of Redox.
A global AtomicUSize counter was added, and a line to switch contexts
on every 10 PIT interrupts in irq.rs.
use context::timeout;
use device::pic;
use device::serial::{COM1, COM2};
+use core::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
+
use time;
+use context;
+
+static PIT_TICKS: AtomicUsize = ATOMIC_USIZE_INIT;
unsafe fn trigger(irq: u8) {
extern {
@@ -46,6 +51,10 @@ interrupt!(pit, {
pic::MASTER.ack();
+ if PIT_TICKS.fetch_add(1, Ordering::SeqCst) % 10 == 0 {
+ context::switch();
+ }
+
// Any better way of doing this?
timeout::trigger();
});
