Group :: Development/Tools
RPM: android-tools
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
Patch: stdatomic.patch
Download
Download
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
@@ -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 <stdbool.h>
#include <cutils/list.h>
--- a/liblog/logger_write.cpp
+++ b/liblog/logger_write.cpp
@@ -15,7 +15,6 @@
*/
#include <errno.h>
-#include <stdatomic.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>