[Small Record] Atomic plus under ARM64

1. Use atomic_add in the code

  • There is no atomic header file under aarch64
  • Compile errors :
/Users/ahfu/code/android/android-ndk-r14b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ ....
.. /..//thread_util.cpp:92:7: error: use of undeclared identifier'atomic_add'
atomic_add(&(obj->m_start_idx), 1);

2. Suspect the problem of clang, try changing to gcc to compile

Add a line in Application.mk:
NDK_TOOLCHAIN ​​:= aarch64-linux-android-4.9< br> Compilation appears:

/Users/ahfu/code/android/android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android -g++ ...
../..//thread_util.cpp:92:40: error:'atomic_add' was not declared in this scope
atomic_add(&(obj->m_start_idx), 1 );

3. When I finally remembered, atomic became a built-in command of gcc

So I changed atomic_add to __sync_fetch_and_add(&(obj->m_start_idx), 1); The problem is solved.

Leave a Comment

Your email address will not be published.