There's some material online about how to write 64 bit atomic code, for example:
How to guarantee 64-bit writes are atomic?
.. but before I go down that road, I'd prefer to use an Android NDK / ARM specific solution if there is one.
I'm porting a C++ engine which needs 32 and 64 bit atomic operations. I researched and implemented the GCC built-in __sync_* functions, but when it came time to link I got these kind of errors for the 64 bit operations:
error: undefined reference to '__sync_fetch_and_or_8'
error: undefined reference to '__sync_lock_test_and_set_8'
error: undefined reference to '__sync_fetch_and_and_8'
error: undefined reference to '__sync_fetch_and_add_8'
error: undefined reference to '__sync_val_compare_and_swap_8'
I'm targetting armeabi-v7a, which I've read has some assembly instructions for 64 bit atomic (ldrexd/strexd), so is there a way to access them via the GCC built-in atomics? If not, what are the other options?
- use a mutex to protect each 64 bit operation
- write assembly code to take advantage of ldrexd/strexd
- pass a super secret flag to the NDK toolchain to enable 64 bit intrinsics?
- wait for ARMv8? :)
Thanks!