From: Ondřej Surý Date: Sun, 18 Mar 2018 14:58:44 +0000 (+0000) Subject: Only require stdatomic.h when compiled with threading support X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1721667a015fd4f678f1f1f561c8ca9b43882511;p=thirdparty%2Fbind9.git Only require stdatomic.h when compiled with threading support --- diff --git a/configure b/configure index f15cfe44e14..525d4cee491 100755 --- a/configure +++ b/configure @@ -19749,21 +19749,18 @@ done # # Machine architecture dependent features # -have_stdatomic=no -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable stdatomic.h" >&5 + +ISC_ATOMIC_LIBS= +if test "$use_threads" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usable stdatomic.h" >&5 $as_echo_n "checking for usable stdatomic.h... " >&6; } -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - -#include #include - int main () { - atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed); - ; return 0; } @@ -19776,10 +19773,9 @@ else fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -ISC_ATOMIC_LIBS= -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if -latomic is needed to use 64-bit stdatomic.h primitives" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if -latomic is needed to use 64-bit stdatomic.h primitives" >&5 $as_echo_n "checking if -latomic is needed to use 64-bit stdatomic.h primitives... " >&6; } -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int @@ -19793,15 +19789,16 @@ _ACEOF if ac_fn_c_try_link "$LINENO"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - ISC_ATOMIC_LIBS="" + ISC_ATOMIC_LIBS="" else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - ISC_ATOMIC_LIBS="-latomic" + ISC_ATOMIC_LIBS="-latomic" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext +fi # use_threads # diff --git a/configure.in b/configure.in index 996322074d0..640d70ed9ad 100644 --- a/configure.in +++ b/configure.in @@ -3888,28 +3888,25 @@ AC_CHECK_FUNCS(nanosleep usleep explicit_bzero) # # Machine architecture dependent features # -have_stdatomic=no -AC_MSG_CHECKING(for usable stdatomic.h) -AC_TRY_COMPILE([ -#include -#include -], -[ -atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed); -], + +ISC_ATOMIC_LIBS= +if test "$use_threads" = "yes"; then + AC_MSG_CHECKING(for usable stdatomic.h) + AC_TRY_COMPILE([#include ], + [atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);], [AC_MSG_RESULT(yes)], [AC_MSG_ERROR([a compiler with atomics support is required])]) -ISC_ATOMIC_LIBS= -AC_MSG_CHECKING(if -latomic is needed to use 64-bit stdatomic.h primitives) -AC_LINK_IFELSE( - [AC_LANG_PROGRAM([#include ], - [atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);])], - [AC_MSG_RESULT(no) - ISC_ATOMIC_LIBS=""], - [AC_MSG_RESULT(yes) - ISC_ATOMIC_LIBS="-latomic"] - ) + AC_MSG_CHECKING(if -latomic is needed to use 64-bit stdatomic.h primitives) + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([#include ], + [atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);])], + [AC_MSG_RESULT(no) + ISC_ATOMIC_LIBS=""], + [AC_MSG_RESULT(yes) + ISC_ATOMIC_LIBS="-latomic"] + ) +fi # use_threads AC_SUBST([ISC_ATOMIC_LIBS]) # diff --git a/lib/isc/include/isc/refcount.h b/lib/isc/include/isc/refcount.h index 4ff05c91645..cdb9f149b76 100644 --- a/lib/isc/include/isc/refcount.h +++ b/lib/isc/include/isc/refcount.h @@ -13,8 +13,6 @@ #ifndef ISC_REFCOUNT_H #define ISC_REFCOUNT_H 1 -#include - #include #include #include @@ -22,6 +20,10 @@ #include #include +#ifdef ISC_PLATFORM_USETHREADS +#include +#endif + /*! \file isc/refcount.h * \brief Implements a locked reference counter. * diff --git a/lib/isc/include/isc/rwlock.h b/lib/isc/include/isc/rwlock.h index e00f851cb4d..1951d06013b 100644 --- a/lib/isc/include/isc/rwlock.h +++ b/lib/isc/include/isc/rwlock.h @@ -16,13 +16,15 @@ /*! \file isc/rwlock.h */ #include -#include #include #include #include #include +#ifdef ISC_PLATFORM_USETHREADS +#include +#endif ISC_LANG_BEGINDECLS diff --git a/lib/isc/stats.c b/lib/isc/stats.c index 4341442fd50..36482835bb7 100644 --- a/lib/isc/stats.c +++ b/lib/isc/stats.c @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -26,6 +25,10 @@ #include #include +#ifdef ISC_PLATFORM_USETHREADS +#include +#endif + #define ISC_STATS_MAGIC ISC_MAGIC('S', 't', 'a', 't') #define ISC_STATS_VALID(x) ISC_MAGIC_VALID(x, ISC_STATS_MAGIC) @@ -36,7 +39,11 @@ */ #define ISC_STATS_LOCKCOUNTERS 0 +#ifdef ISC_PLATFORM_USETHREADS typedef atomic_int_fast64_t isc_stat_t; +#else +typedef isc_int64_t isc_stat_t; +#endif struct isc_stats { /*% Unlocked */ @@ -185,6 +192,7 @@ void isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) { REQUIRE(ISC_STATS_VALID(stats)); REQUIRE(counter < stats->ncounters); +#ifdef ISC_PLATFORM_USETHREADS /* * We use a "read" lock to prevent other threads from reading the * counter while we "writing" a counter field. The write access itself @@ -200,6 +208,9 @@ isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) { #if ISC_STATS_LOCKCOUNTERS isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_write); #endif +#else /* ISC_PLATFORM_USETHREADS */ + stats->counters[counter]++; +#endif /* ISC_PLATFORM_USETHREADS */ } void @@ -207,6 +218,7 @@ isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter) { REQUIRE(ISC_STATS_VALID(stats)); REQUIRE(counter < stats->ncounters); +#ifdef ISC_PLATFORM_USETHREADS #if ISC_STATS_LOCKCOUNTERS isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_write); #endif @@ -217,6 +229,9 @@ isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter) { #if ISC_STATS_LOCKCOUNTERS isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_write); #endif +#else /* ISC_PLATFORM_USETHREADS */ + stats->counters[counter]--; +#endif /* ISC_PLATFORM_USETHREADS */ } void @@ -227,6 +242,7 @@ isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn, REQUIRE(ISC_STATS_VALID(stats)); +#ifdef ISC_PLATFORM_USETHREADS /* * We use a "write" lock before "reading" the statistics counters as * an exclusive lock. @@ -251,6 +267,14 @@ isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn, continue; dump_fn((isc_statscounter_t)i, stats->copiedcounters[i], arg); } +#else /* ISC_PLATFORM_USETHREADS */ + for (i = 0; i < stats->ncounters; i++) { + if ((options & ISC_STATSDUMP_VERBOSE) == 0 && + stats->counters[i] == 0) + continue; + dump_fn((isc_statscounter_t)i, stats->counters[i], arg); + } +#endif /* ISC_PLATFORM_USETHREADS */ } void @@ -260,6 +284,7 @@ isc_stats_set(isc_stats_t *stats, isc_uint64_t val, REQUIRE(ISC_STATS_VALID(stats)); REQUIRE(counter < stats->ncounters); +#ifdef ISC_PLATFORM_USETHREADS #if ISC_STATS_LOCKCOUNTERS isc_rwlock_lock(&stats->counterlock, isc_rwlocktype_write); #endif @@ -270,4 +295,7 @@ isc_stats_set(isc_stats_t *stats, isc_uint64_t val, #if ISC_STATS_LOCKCOUNTERS isc_rwlock_unlock(&stats->counterlock, isc_rwlocktype_write); #endif +#else /* ISC_PLATFORM_USETHREADS */ + stats->counters[counter] = val; +#endif /* ISC_PLATFORM_USETHREADS */ }