3 ms·
Wait, is it even possible to do an atomic volatile modify of a MMIO register? Sure, x86 has LOCK prefix but would it work with memory-mapped stuff?
by Joker_vD 3y ago
Wait, is it even possible to do an atomic volatile modify of a MMIO register? Sure, x86 has LOCK prefix but would it work with memory-mapped stuff?
- auxym 3y agoFrom my understanding, the only thing volatile does (IIRC this is implementation specified as the standard is vague) is prevent the compiler from optimizing out reads or writes when it thinks they are "useless". That is, is tells the compiler "this memory location may change independently of that the code is doing, so you always need to read or write it when I say so". Atomicity is sort of a different thing. You might need things like critical sections (disable interrupts) or memory fencing for the read-modify-write cycle.
- matt-noonan 3y agoThere are some interesting solutions out there, such as bit-banding used in some ARM Cortex CPUs. This maps entire bytes in the high part of the address space to single bits in the low part of the address space, so that you can make an atomic set or clear of a single physical bit by writing to a byte of memory. https://spin.atomicobject.com/bit-banding/ https://spin.atomicobject.com/bit-banding/