Upstream-Status: Pending

Description: Fix incompatibility between <stdatomic.h> and <atomic>
 This 2 headers combined will cause errors for both GCC and Clang. This patch
 makes sure only one of them is present at any time.
Bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932
Bug: https://reviews.llvm.org/D45470
--- a/system/core/libcutils/include/cutils/trace.h
+++ b/system/core/libcutils/include/cutils/trace.h
@@ -18,7 +18,14 @@
 #define _LIBS_CUTILS_TRACE_H
 
 #include <inttypes.h>
+#ifdef __cplusplus
+#include <atomic>
+using std::atomic_bool;
+using std::atomic_load_explicit;
+using std::memory_order_acquire;
+#else
 #include <stdatomic.h>
+#endif
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
--- a/system/core/libcutils/include/cutils/atomic.h
+++ b/system/core/libcutils/include/cutils/atomic.h
@@ -19,7 +19,23 @@
 
 #include <stdint.h>
 #include <sys/types.h>
+#ifdef __cplusplus
+#include <atomic>
+using std::atomic_compare_exchange_strong_explicit;
+using std::atomic_fetch_add_explicit;
+using std::atomic_fetch_or_explicit;
+using std::atomic_fetch_sub_explicit;
+using std::atomic_int_least32_t;
+using std::atomic_load_explicit;
+using std::atomic_store_explicit;
+using std::atomic_thread_fence;
+using std::memory_order::memory_order_acquire;
+using std::memory_order::memory_order_relaxed;
+using std::memory_order::memory_order_release;
+using std::memory_order::memory_order_seq_cst;
+#else
 #include <stdatomic.h>
+#endif
 
 #ifndef ANDROID_ATOMIC_INLINE
 #define ANDROID_ATOMIC_INLINE static inline
--- a/system/core/liblog/logger.h
+++ b/system/core/liblog/logger.h
@@ -16,7 +16,13 @@
 
 #pragma once
 
+#ifdef __cplusplus
+#include <atomic>
+using std::atomic_int;
+using std::atomic_uintptr_t;
+#else
 #include <stdatomic.h>
+#endif
 #include <sys/cdefs.h>
 
 #include <log/log.h>
