The system registers have associated functions which do a read-modify-write cycle, but the functions are not unsafe to call and do not require the (unsafe) creation of an object that represents unique ownership of that register. This means safe code can have undefined behaviour, through the main thread doing a modify on a register, which is interrupted by an exception that also does a modify on the same register. That's not ideal.
Rather than model each register as an object with a unique owner, I think the modify function should be unsafe.
I think the read and write functions can remain safe, because the effect would be no worse than conflicting store operations on an atomic variable (which is safe).
The system registers have associated functions which do a read-modify-write cycle, but the functions are not unsafe to call and do not require the (unsafe) creation of an object that represents unique ownership of that register. This means safe code can have undefined behaviour, through the main thread doing a modify on a register, which is interrupted by an exception that also does a modify on the same register. That's not ideal.
Rather than model each register as an object with a unique owner, I think the
modifyfunction should be unsafe.I think the
readandwritefunctions can remain safe, because the effect would be no worse than conflictingstoreoperations on an atomic variable (which is safe).