Fix incompatibility between <stdatomic.h> and <atomic>
authorAndroid Tools Maintainers <android-tools-devel@lists.alioth.debian.org>
Thu, 24 Feb 2022 16:58:51 +0000 (16:58 +0000)
committerRoger Shimizu <rosh@debian.org>
Thu, 24 Feb 2022 16:58:51 +0000 (16:58 +0000)
Bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60932
Bug: https://reviews.llvm.org/D45470

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.

Gbp-Pq: Topic system/core
Gbp-Pq: Name stdatomic.patch

system/core/libcutils/include/cutils/atomic.h
system/core/libcutils/include/cutils/trace.h
system/core/liblog/logger.h

index 0c88bfedd3a2a987a21e8daddebf3f3fbf3ed92c..43cc5b3a466390c65d50017ff7ca58185f2ee437 100644 (file)
 
 #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
index e12c32cff1f5cc001830ce53239705b482cd6174..4e8b649717b9edd82029f93618570a31ae2c3a3c 100644 (file)
 #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>
index ddff19dd5a02541aec1723953795bd42140a355e..554e45e5de3c3f546e64431c10340bf2532c460f 100644 (file)
 
 #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>