NadavRub
NadavRub

Reputation: 2610

Native Android, Interlocked/Atomic operations

Interlocked/Atomic operations are CPU specific.

Is there any common baseline requirement by all Android supporting hardware as far as for interlocked operations?

Are there any interlocked operations supported by all Android devices?

Is there any Android equivalent to Windows' InterlockedExchange?

Any help will be appreciated.

Upvotes: 2

Views: 4459

Answers (3)

Andrey Starodubtsev
Andrey Starodubtsev

Reputation: 5292

There's stdatomic header in latest editions of ndk, so if you use GNU or LLVM cxx module, it is possible to use this standard C++11 header. You cannot use it with STLport however - it has no such header. Do not forget to add libatomic to LOCAL_LDLIBS (see https://developer.android.com/ndk/guides/cpp-support.html for details).

Upvotes: 0

beetoom
beetoom

Reputation: 489

You can also use GCC atomic builtins.

Upvotes: 1

Mārtiņš Možeiko
Mārtiņš Možeiko

Reputation: 12927

You can use __atomic_swap for InterlockedExchange functionality.

Read docs/ANDROID-ATOMICS.html file from NDK distribution for more info.

Upvotes: 3

Related Questions