Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

Module critical_section

Module critical_section 

Source
Expand description

Critical sections: run code with CPU interrupts masked.

On the PS1 a critical section clears COP0 SR.IEc for its duration and puts the previous value back afterwards, so sections nest. psx-rt’s own interrupt handler is assembly that touches no Rust state, so the SDK does not need one; games that install a Rust IRQ handler do, to share data with it.

The shape follows the critical-section crate: acquire and release are the raw pair, with the scoped form, and Mutex hands out a shared reference only while a CriticalSection token is alive. With psx-rt’s critical-section feature the same pair is also registered as that crate’s implementation, so critical_section::with in any dependency masks interrupts here too.

Host builds (tests, tools) serialise through a spin lock instead, so the same code stays sound under a multi-threaded test runner.

Structs§

CriticalSection
Proof that the current code runs inside a critical section.
Mutex
Data shared with interrupt code, reachable only inside a critical section.
RestoreState
What release needs to put back: whether interrupts were enabled.

Functions§

acquire⚠
Enter a critical section, returning the state to restore on exit.
release⚠
Leave a critical section entered by acquire.
with
Run f with interrupts masked, then restore the previous state.