am e505cc66: Merge "Make stdatomic.h work with gcc4.6 host compiler"
				
					
				
			* commit 'e505cc66a6e03f4ba460de3500f8b272421482c1': Make stdatomic.h work with gcc4.6 host compiler
This commit is contained in:
		@@ -32,8 +32,20 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <sys/cdefs.h>
 | 
					#include <sys/cdefs.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__cplusplus) && defined(_USING_LIBCXX) && \
 | 
					
 | 
				
			||||||
    (__has_feature(cxx_atomic) || _GNUC_VER >= 407)
 | 
					#if defined(__cplusplus) && defined(_USING_LIBCXX)
 | 
				
			||||||
 | 
					# ifdef __clang__
 | 
				
			||||||
 | 
					#  if __has_feature(cxx_atomic)
 | 
				
			||||||
 | 
					#   define _STDATOMIC_HAVE_ATOMIC
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					# else /* gcc */
 | 
				
			||||||
 | 
					#  if __GNUC_PREREQ(4, 7)
 | 
				
			||||||
 | 
					#   define _STDATOMIC_HAVE_ATOMIC
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					# endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef _STDATOMIC_HAVE_ATOMIC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* We have a usable C++ <atomic>; use it instead.  */
 | 
					/* We have a usable C++ <atomic>; use it instead.  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -46,6 +58,7 @@
 | 
				
			|||||||
        /* included.  The definitions in <atomic> themselves see      */
 | 
					        /* included.  The definitions in <atomic> themselves see      */
 | 
				
			||||||
        /* the old definition, as they should.                        */
 | 
					        /* the old definition, as they should.                        */
 | 
				
			||||||
        /* Client code sees the following definition.                 */
 | 
					        /* Client code sees the following definition.                 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define _Atomic(t) std::atomic<t>
 | 
					#define _Atomic(t) std::atomic<t>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using std::atomic_is_lock_free;
 | 
					using std::atomic_is_lock_free;
 | 
				
			||||||
@@ -136,15 +149,25 @@ using std::atomic_uintmax_t;
 | 
				
			|||||||
# include <uchar.h>  /* For char16_t and char32_t.              */
 | 
					# include <uchar.h>  /* For char16_t and char32_t.              */
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __clang__
 | 
				
			||||||
# if __has_extension(c_atomic) || __has_extension(cxx_atomic)
 | 
					# if __has_extension(c_atomic) || __has_extension(cxx_atomic)
 | 
				
			||||||
#  define       __CLANG_ATOMICS
 | 
					#  define       __CLANG_ATOMICS
 | 
				
			||||||
#elif __GNUC_PREREQ(4, 7)
 | 
					 | 
				
			||||||
#define	__GNUC_ATOMICS
 | 
					 | 
				
			||||||
#elif defined(__GNUC__)
 | 
					 | 
				
			||||||
#define	__SYNC_ATOMICS
 | 
					 | 
				
			||||||
# else
 | 
					# else
 | 
				
			||||||
#  error "stdatomic.h does not support your compiler"
 | 
					#  error "stdatomic.h does not support your compiler"
 | 
				
			||||||
# endif
 | 
					# endif
 | 
				
			||||||
 | 
					# if __has_builtin(__sync_swap)
 | 
				
			||||||
 | 
					#  define __HAS_BUILTIN_SYNC_SWAP
 | 
				
			||||||
 | 
					# endif
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					# if __GNUC_PREREQ(4, 7)
 | 
				
			||||||
 | 
					#  define	__GNUC_ATOMICS
 | 
				
			||||||
 | 
					# else
 | 
				
			||||||
 | 
					#  define	__SYNC_ATOMICS
 | 
				
			||||||
 | 
					#  ifdef __cplusplus
 | 
				
			||||||
 | 
					#   define       __ATOMICS_AVOID_DOT_INIT
 | 
				
			||||||
 | 
					#  endif
 | 
				
			||||||
 | 
					# endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * 7.17.1 Atomic lock-free macros.
 | 
					 * 7.17.1 Atomic lock-free macros.
 | 
				
			||||||
@@ -152,33 +175,53 @@ using std::atomic_uintmax_t;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#ifdef __GCC_ATOMIC_BOOL_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_BOOL_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_BOOL_LOCK_FREE		__GCC_ATOMIC_BOOL_LOCK_FREE
 | 
					#define	ATOMIC_BOOL_LOCK_FREE		__GCC_ATOMIC_BOOL_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_BOOL_LOCK_FREE           2 /* For all modern platforms */
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_CHAR_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_CHAR_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_CHAR_LOCK_FREE		__GCC_ATOMIC_CHAR_LOCK_FREE
 | 
					#define	ATOMIC_CHAR_LOCK_FREE		__GCC_ATOMIC_CHAR_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_CHAR_LOCK_FREE           2
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_CHAR16_T_LOCK_FREE	__GCC_ATOMIC_CHAR16_T_LOCK_FREE
 | 
					#define	ATOMIC_CHAR16_T_LOCK_FREE	__GCC_ATOMIC_CHAR16_T_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_CHAR16_T_LOCK_FREE       2
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_CHAR32_T_LOCK_FREE	__GCC_ATOMIC_CHAR32_T_LOCK_FREE
 | 
					#define	ATOMIC_CHAR32_T_LOCK_FREE	__GCC_ATOMIC_CHAR32_T_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_CHAR32_T_LOCK_FREE       2
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_WCHAR_T_LOCK_FREE	__GCC_ATOMIC_WCHAR_T_LOCK_FREE
 | 
					#define	ATOMIC_WCHAR_T_LOCK_FREE	__GCC_ATOMIC_WCHAR_T_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_WCHAR_T_LOCK_FREE        2
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_SHORT_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_SHORT_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_SHORT_LOCK_FREE		__GCC_ATOMIC_SHORT_LOCK_FREE
 | 
					#define	ATOMIC_SHORT_LOCK_FREE		__GCC_ATOMIC_SHORT_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_SHORT_LOCK_FREE          2
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_INT_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_INT_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_INT_LOCK_FREE		__GCC_ATOMIC_INT_LOCK_FREE
 | 
					#define	ATOMIC_INT_LOCK_FREE		__GCC_ATOMIC_INT_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_INT_LOCK_FREE            2
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_LONG_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_LONG_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_LONG_LOCK_FREE		__GCC_ATOMIC_LONG_LOCK_FREE
 | 
					#define	ATOMIC_LONG_LOCK_FREE		__GCC_ATOMIC_LONG_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_LONG_LOCK_FREE           2
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_LLONG_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_LLONG_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_LLONG_LOCK_FREE		__GCC_ATOMIC_LLONG_LOCK_FREE
 | 
					#define	ATOMIC_LLONG_LOCK_FREE		__GCC_ATOMIC_LLONG_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_LLONG_LOCK_FREE          1 /* maybe */
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef __GCC_ATOMIC_POINTER_LOCK_FREE
 | 
					#ifdef __GCC_ATOMIC_POINTER_LOCK_FREE
 | 
				
			||||||
#define	ATOMIC_POINTER_LOCK_FREE	__GCC_ATOMIC_POINTER_LOCK_FREE
 | 
					#define	ATOMIC_POINTER_LOCK_FREE	__GCC_ATOMIC_POINTER_LOCK_FREE
 | 
				
			||||||
 | 
					#elif defined(__SYNC_ATOMICS)
 | 
				
			||||||
 | 
					#define	ATOMIC_POINTER_LOCK_FREE        2
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -189,7 +232,11 @@ using std::atomic_uintmax_t;
 | 
				
			|||||||
#define	ATOMIC_VAR_INIT(value)		(value)
 | 
					#define	ATOMIC_VAR_INIT(value)		(value)
 | 
				
			||||||
#define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
 | 
					#define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
					#ifdef __ATOMICS_AVOID_DOT_INIT
 | 
				
			||||||
 | 
					#define	ATOMIC_VAR_INIT(value)		{ value }
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
#define	ATOMIC_VAR_INIT(value)		{ .__val = (value) }
 | 
					#define	ATOMIC_VAR_INIT(value)		{ .__val = (value) }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
#define	atomic_init(obj, value)		((void)((obj)->__val = (value)))
 | 
					#define	atomic_init(obj, value)		((void)((obj)->__val = (value)))
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -289,7 +336,7 @@ atomic_signal_fence(memory_order __order __attribute__((unused)))
 | 
				
			|||||||
 * 7.17.6 Atomic integer types.
 | 
					 * 7.17.6 Atomic integer types.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !__has_extension(c_atomic) && !__has_extension(cxx_atomic)
 | 
					#ifndef __CLANG_ATOMICS
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * No native support for _Atomic(). Place object in structure to prevent
 | 
					 * No native support for _Atomic(). Place object in structure to prevent
 | 
				
			||||||
 * most forms of direct non-atomic access.
 | 
					 * most forms of direct non-atomic access.
 | 
				
			||||||
@@ -410,7 +457,7 @@ typedef _Atomic(uintmax_t)		atomic_uintmax_t;
 | 
				
			|||||||
    desired, success, failure)						\
 | 
					    desired, success, failure)						\
 | 
				
			||||||
	atomic_compare_exchange_strong_explicit(object, expected,	\
 | 
						atomic_compare_exchange_strong_explicit(object, expected,	\
 | 
				
			||||||
		desired, success, failure)
 | 
							desired, success, failure)
 | 
				
			||||||
#if __has_builtin(__sync_swap)
 | 
					#ifdef __HAS_BUILTIN_SYNC_SWAP
 | 
				
			||||||
/* Clang provides a full-barrier atomic exchange - use it if available. */
 | 
					/* Clang provides a full-barrier atomic exchange - use it if available. */
 | 
				
			||||||
#define	atomic_exchange_explicit(object, desired, order)		\
 | 
					#define	atomic_exchange_explicit(object, desired, order)		\
 | 
				
			||||||
	((void)(order), __sync_swap(&(object)->__val, desired))
 | 
						((void)(order), __sync_swap(&(object)->__val, desired))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,14 +63,17 @@ TEST(stdatomic, atomic_signal_fence) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
TEST(stdatomic, atomic_is_lock_free) {
 | 
					TEST(stdatomic, atomic_is_lock_free) {
 | 
				
			||||||
  atomic_char small;
 | 
					  atomic_char small;
 | 
				
			||||||
  atomic_intmax_t big;
 | 
					 | 
				
			||||||
  ASSERT_TRUE(atomic_is_lock_free(&small));
 | 
					  ASSERT_TRUE(atomic_is_lock_free(&small));
 | 
				
			||||||
 | 
					#if defined(__clang__) || __GNUC_PREREQ(4, 7)
 | 
				
			||||||
 | 
					  // Otherwise stdatomic.h doesn't handle this.
 | 
				
			||||||
 | 
					  atomic_intmax_t big;
 | 
				
			||||||
  // atomic_intmax_t(size = 64) is not lock free on mips32.
 | 
					  // atomic_intmax_t(size = 64) is not lock free on mips32.
 | 
				
			||||||
#if defined(__mips__) && !defined(__LP64__)
 | 
					#if defined(__mips__) && !defined(__LP64__)
 | 
				
			||||||
  ASSERT_FALSE(atomic_is_lock_free(&big));
 | 
					  ASSERT_FALSE(atomic_is_lock_free(&big));
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
  ASSERT_TRUE(atomic_is_lock_free(&big));
 | 
					  ASSERT_TRUE(atomic_is_lock_free(&big));
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(stdatomic, atomic_flag) {
 | 
					TEST(stdatomic, atomic_flag) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user