在C语言中是否有用于原子读取-修改-写入的函数?我想要在单个原子块中读取一个值,然后将其设置为0。
对于C ++,有std::atomic :: exchange()正是我要找的东西。在C中是否有类似的内容?
以下是代码:
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;
}
目标架构是PowerPC。
感谢您的帮助!