]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Only require stdatomic.h when compiled with threading support
authorOndřej Surý <ondrej@sury.org>
Sun, 18 Mar 2018 14:58:44 +0000 (14:58 +0000)
committerOndřej Surý <ondrej@sury.org>
Thu, 24 May 2018 08:37:46 +0000 (10:37 +0200)
configure
configure.in
lib/isc/include/isc/refcount.h
lib/isc/include/isc/rwlock.h
lib/isc/stats.c

index f15cfe44e1491132efbc082f7a895ce64ebca833..525d4cee4911d90c4b861712be9eb4ba9ab341f1 100755 (executable)
--- 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 <stdio.h>
 #include <stdatomic.h>
-
 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 <stdatomic.h>
 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
 
 
 #
index 996322074d09b05f9e23392b0245479e7445be54..640d70ed9adb64598a450f90a99fa62fb22159de 100644 (file)
@@ -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 <stdio.h>
-#include <stdatomic.h>
-],
-[
-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 <stdatomic.h>],
+                      [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 <stdatomic.h>],
-                        [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 <stdatomic.h>],
+                                [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])
 
 #
index 4ff05c916456e10ee44a156c3cb20abf5c6ba106..cdb9f149b7616ce2a48f13b904d7a7796452c4b1 100644 (file)
@@ -13,8 +13,6 @@
 #ifndef ISC_REFCOUNT_H
 #define ISC_REFCOUNT_H 1
 
-#include <stdatomic.h>
-
 #include <isc/assertions.h>
 #include <isc/error.h>
 #include <isc/lang.h>
 #include <isc/platform.h>
 #include <isc/types.h>
 
+#ifdef ISC_PLATFORM_USETHREADS
+#include <stdatomic.h>
+#endif
+
 /*! \file isc/refcount.h
  * \brief Implements a locked reference counter.
  *
index e00f851cb4d1789c8e934578368059bf9e690a7e..1951d06013b29d6d638692a4d543f19a5596c4eb 100644 (file)
 /*! \file isc/rwlock.h */
 
 #include <stdint.h>
-#include <stdatomic.h>
 
 #include <isc/condition.h>
 #include <isc/lang.h>
 #include <isc/platform.h>
 #include <isc/types.h>
 
+#ifdef ISC_PLATFORM_USETHREADS
+#include <stdatomic.h>
+#endif
 
 ISC_LANG_BEGINDECLS
 
index 4341442fd50eb061724e2912c6811eb8b05c393e..36482835bb7f89b4ff810362605585780911c027 100644 (file)
@@ -15,7 +15,6 @@
 #include <config.h>
 
 #include <string.h>
-#include <stdatomic.h>
 
 #include <isc/buffer.h>
 #include <isc/magic.h>
 #include <isc/stats.h>
 #include <isc/util.h>
 
+#ifdef ISC_PLATFORM_USETHREADS
+#include <stdatomic.h>
+#endif
+
 #define ISC_STATS_MAGIC                        ISC_MAGIC('S', 't', 'a', 't')
 #define ISC_STATS_VALID(x)             ISC_MAGIC_VALID(x, ISC_STATS_MAGIC)
 
  */
 #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 */
 }