1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
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/libcutils/include/cutils/trace.h
+++ b/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/libcutils/include/cutils/atomic.h
+++ b/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/liblog/logger.h
+++ b/liblog/logger.h
@@ -17,7 +17,13 @@
#ifndef _LIBLOG_LOGGER_H__
#define _LIBLOG_LOGGER_H__
+#ifdef __cplusplus
+#include <atomic>
+using std::atomic_int;
+using std::atomic_uintptr_t;
+#else
#include <stdatomic.h>
+#endif
#include <stdbool.h>
#include <cutils/list.h>
|