2 years ago

#60044

test-img

PineLel

Atomic load, compare, modify, write - in C99 on ARM

I'm writing some embedded code, that can be interrupted by an external event (IRQ). Basically, what I need to do, is load a variable, compare it, load it, modify and store. However, if such interrupt occurs, this variable may be modified between my load/compare or load/modify operations. Thus, I need to make this operation atomic, to avoid unexpected behavior. Basically, my code is something like:

if(a>0) a--;

Now, I know, that C11 standard introduces atomic operations, and thet GCC has __atomic built-ins. However, this code must not be GCC-specific, and must adhere to C99 standard. How do I accomplish atomicity on ARM, without using GCC built-ins and C11 atomic operations? Thanks

c

arm

atomic

c99

0 Answers

Your Answer

Accepted video resources