#
# 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;
}
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
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
#
#
# 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])
#
#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 */
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
#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
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
#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
REQUIRE(ISC_STATS_VALID(stats));
+#ifdef ISC_PLATFORM_USETHREADS
/*
* We use a "write" lock before "reading" the statistics counters as
* an exclusive lock.
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
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
#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 */
}