Search code examples
linux-kernelarmarm64atomicmemory-barriers

why does arm atomic_[read/write] operations implemented as volatile pointers?


He is example of atomic_read implementation:

#define atomic_read(v) (*(volatile int *)&(v)->counter)                                  

Also, should we explicitly use memory barriers for atomic operations on arm?


Solution

  • He is example of atomic_read implementation:

    A problematic one actually, which assumes that a cast is not a nop, which isn't guaranteed.

    Also, should we explicitly use memory barriers for atomic operations on arm?

    Probably. It depends on what you are doing and what you are expecting.