From 524ff11d3c7cc5c35ce6c6568cbeb3c9309dc482 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Fri, 29 Oct 2021 15:04:55 +0000 Subject: apr_atomic: Use __atomic builtins when available. Unlike Intel's atomic builtins (__sync_*), the more recent __atomic builtins provide atomic load and store for weakly ordered architectures like ARM32 or powerpc[64], so use them when available (gcc 4.6.3+). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1894618 13f79535-47bb-0310-9956-ffa450edef68 --- include/apr.h.in | 21 +++++++++++++++++++++ include/apr.hnw | 1 + include/apr.hw | 1 + include/apr.hwc | 1 + include/apr_general.h | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+) (limited to 'include') diff --git a/include/apr.h.in b/include/apr.h.in index c498376d9..efb791a22 100644 --- a/include/apr.h.in +++ b/include/apr.h.in @@ -45,6 +45,26 @@ * are platform specific and should NOT be relied upon! */ +/* So that we can test for clang features */ +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_extension +#define __has_extension __has_feature +#endif +#ifndef __has_include +#define __has_include(x) 0 +#endif +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + +#if !(defined(__attribute__) \ + || (defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && \ + __GNUC_MINOR__ >= 4)))) +#define __attribute__(x) +#endif + /* So that we can use inline on some critical functions, and use * GNUC attributes (such as to get -Wall warnings for printf-like * functions). Only do this in gcc 2.7 or later ... it may work @@ -70,6 +90,7 @@ #endif #define APR_HAVE_ARPA_INET_H @arpa_ineth@ +#define APR_HAVE_ASSERT_H @asserth@ #define APR_HAVE_CONIO_H @conioh@ #define APR_HAVE_CRYPT_H @crypth@ #define APR_HAVE_CTYPE_H @ctypeh@ diff --git a/include/apr.hnw b/include/apr.hnw index 6db0c9b5e..10ebb390a 100644 --- a/include/apr.hnw +++ b/include/apr.hnw @@ -80,6 +80,7 @@ extern "C" { #endif #define ENUM_BITFIELD(e,n,w) signed int n : w +#define APR_HAVE_ASSERT_H 1 #define APR_HAVE_CONIO_H 0 #define APR_HAVE_CRYPT_H 0 #define APR_HAVE_CTYPE_H 1 diff --git a/include/apr.hw b/include/apr.hw index 7cdfd1570..b0c2fe524 100644 --- a/include/apr.hw +++ b/include/apr.hw @@ -130,6 +130,7 @@ #endif #define APR_HAVE_ARPA_INET_H 0 +#define APR_HAVE_ASSERT_H 1 #define APR_HAVE_CONIO_H APR_NOT_IN_WCE #define APR_HAVE_CRYPT_H 0 #define APR_HAVE_CTYPE_H APR_NOT_IN_WCE diff --git a/include/apr.hwc b/include/apr.hwc index 03bcd5e8e..8362fffcb 100644 --- a/include/apr.hwc +++ b/include/apr.hwc @@ -129,6 +129,7 @@ #define APR_NOT_IN_WCE 1 #endif +#define APR_HAVE_ASSERT_H 1 #define APR_HAVE_ARPA_INET_H 0 #define APR_HAVE_CONIO_H APR_NOT_IN_WCE #define APR_HAVE_CRYPT_H 0 diff --git a/include/apr_general.h b/include/apr_general.h index 4f2a6e8c4..5e53bb63d 100644 --- a/include/apr_general.h +++ b/include/apr_general.h @@ -29,6 +29,9 @@ #include "apr_pools.h" #include "apr_errno.h" +#if APR_HAVE_ASSERT_H +#include +#endif #if APR_HAVE_SIGNAL_H #include #endif @@ -112,6 +115,42 @@ typedef enum { APR_WAIT_READ, APR_WAIT_WRITE } apr_wait_type_t; #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field) #endif +/** + * Compile time assertions. + * @param predicate static condition + * @param errstring static error message (literal) + */ +#if defined(static_assert) \ + || __has_builtin(static_assert) \ + || (defined(__cplusplus) && (__cplusplus >= 201103L || \ + __has_extension(cxx_static_assert))) \ + || (defined(_MSC_VER ) && _MSC_VER >= 1600) +#define APR_STATIC_ASSERT static_assert + +#elif defined(_Static_assert) \ + || __has_builtin(_Static_assert) \ + || __has_extension(c_static_assert) \ + || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && \ + __GNUC_MINOR__ >= 6))) +#define APR_STATIC_ASSERT _Static_assert + +#else /* !static_assert && !_Static_assert */ +#define APR__STATIC_CONCAT_(x, y) x##y +#define APR__STATIC_CONCAT(x, y) APR__STATIC_CONCAT_(x, y) +#if defined(__COUNTER__) +#define APR_STATIC_ASSERT(predicate, errstring) \ + typedef struct { \ + int static_assert_failure:!!(predicate)*2-1; \ + } APR__STATIC_CONCAT(static_assert_test_, __COUNTER__); +#else /* !__COUNTER__ */ +#define APR_STATIC_ASSERT(predicate, errstring) \ + typedef struct { \ + int static_assert_failure:!!(predicate)*2-1; \ + } APR__STATIC_CONCAT(static_assert_test_, __LINE__); +#endif /* !__COUNTER__ */ + +#endif /* !static_assert && !_Static_assert */ + #ifndef DOXYGEN /* A couple of prototypes for functions in case some platform doesn't -- cgit v1.2.1