#174964 - shotgunninja - Tue Aug 10, 2010 6:06 pm
Hello, my name is Nick, and I've been working on a game engine for the DS in (gasp) C/C++. However, I'm trying to add Interrupt-Safe (aka Thread-Safe, but for Interrupt Handlers) data structures to my engine, and in order to make them truly safe 100% of the time, I need to have access to an atomic Compare-and-Swap instruction. Is there one in the instruction set of the DS' ARM9 processor?
Essentially, I need to be able to do this without interrupting and WITHOUT DISABLING REG_IME:
Essentially, I need to be able to do this without interrupting and WITHOUT DISABLING REG_IME:
Code: |
// As a C function: bool CompareAndSwap(uint32& dest, uint32 oldVal, uint32 newVal) { if (dest != oldVal) { return false; } else { dest = newVal; return true; } } // As register pseudocode: CAS(Rd,Ro,Rn): SREG[EQ] := (Rd EQ Ro); Rd := Rn if (Rd EQ Ro); |