Reputation: 1005
I am writing an atomic increment function for int64_t type that works on many different OS / CPU combinations. For example, on Windows I can use InterlockedIncrement64, on OS X I can use OSAtomicIncrement64Barrier, and on Linux variants I can use GCC built-in __sync_fetch_and_add.
However, when cross-compiling with GCC for MIPS 32-bit architecture, I encounter a link error regarding missing reference to __sync_fetch_and_add_8. Some quick Googling showed that the MIPS 32-bit architecture does not support 64-bit atomic increment instruction (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56300). The suggestion in that bug report to link against libatomic does not seem to work, which may be because I am still on GCC 4.7.
I know that I can always resort to a pthread mutex to protect the increment logic, but this is dramatically slower than taking advantage of a native instruction.
Do you have any recommendation on how to achieve the 64-bit atomic increment in any other way for the MIPS 32-bit architecture?
Upvotes: 3
Views: 1294
Reputation: 1536
I encountered the similar problem when using __atomic
undefined reference to `__atomic_fetch_add_8'
I solved it by linking with libatomic.
BTW, my mipsel cross compiler is GCC 4.8.1
See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56300
Upvotes: 1