Are there any functions in C to do atomic read-modify-write? I'm looking to read a value, then set to 0, in a single atomic block.
For C++ there is std::atomic::exchange() which is exactly what I'm looking for. Is there something equivalent in C?
Here's the code:
void interruptHandler(void) {
/* Callback attached to 3rd party device driver, indicating hardware fault */
/* Set global variable bit masked flag to indicate interrupt */
faultsBitMask |= 0x1;
}
void auditPoll(*faults) {
*faults = faultsBitMask;
/* !!! Need to prevent interrupt pre-empt here !!! */
/* Combine these two lines to a single read-modify-write? */
faultsBitMask = 0;
}
The target architecture is PowerPC.
Thanks for the help!