AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE
+# Check if the selected C compiler supports atomic builtins
+AE_CC_ATOMIC_BUILTINS
+
+
## ##
## C++ compiler checks ##
## ##
AE_FEATURE_DEFAULT_DISABLE
AE_FEATURE([cds-lfht-iter-debug], [Enable extra debugging checks for lock-free hash table iterator traversal. Alters the rculfhash ABI. Make sure to compile both library and application with matching configuration.])
+# Use compiler atomic builtins, when disabled use our legacy uatomic implementation.
+# Disabled by default
+AE_FEATURE_DEFAULT_DISABLE
+AE_FEATURE([compiler-atomic-builtins], [Enable the use of compiler atomic builtins.])
+
# When given, add -Werror to WARN_CFLAGS and WARN_CXXFLAGS.
# Disabled by default
AE_FEATURE_DEFAULT_DISABLE
AC_DEFINE([CONFIG_CDS_LFHT_ITER_DEBUG], [1], [Enable extra debugging checks for lock-free hash table iterator traversal. Alters the rculfhash ABI. Make sure to compile both library and application with matching configuration.])
])
+AE_IF_FEATURE_ENABLED([compiler-atomic-builtins], [
+ AC_DEFINE([CONFIG_RCU_USE_ATOMIC_BUILTINS], [1], [Use compiler atomic builtins.])
+])
## ##
## Set automake variables for optional feature conditionnals in Makefile.am ##
AM_CONDITIONAL([ENABLE_EXAMPLES], AE_IS_FEATURE_ENABLED([shared]))
+## ##
+## Check for optional features dependencies ##
+## ##
+
+
+AE_IF_FEATURE_ENABLED([compiler-atomic-builtins], [
+ AS_IF([test "x$ae_cv_cc_atomic_builtins" != xyes], [
+ AC_MSG_ERROR([The compiler does not support atomic builtins.])
+ ])
+])
+
## ##
## Substitute variables for use in Makefile.am ##
## ##
AE_PPRINT_PROP_BOOL([Multi-flavor support], 1)
+# atomic builtins enabled/disabled
+AE_IS_FEATURE_ENABLED([compiler-atomic-builtins]) && value=1 || value=0
+AE_PPRINT_PROP_BOOL([Use compiler atomic builtins], $value)
+
report_bindir="`eval eval echo $bindir`"
report_libdir="`eval eval echo $libdir`"
--- /dev/null
+# SYNOPSIS
+#
+# AE_CC_ATOMIC_BUILTINS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# LICENSE
+#
+# Copyright (c) 2023 Michael Jeanson <mjeanson@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 1
+
+AC_DEFUN([AE_CC_ATOMIC_BUILTINS], [
+AC_REQUIRE([AC_PROG_CC])
+AC_LANG_PUSH([C])
+
+AC_CACHE_CHECK(
+ [whether $CC supports atomic builtins],
+ [ae_cv_cc_atomic_builtins],
+ [
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
+ int x, y;
+ ],[
+ __atomic_store_n(&x, 0, __ATOMIC_RELAXED);
+ __atomic_load_n(&x, __ATOMIC_RELAXED);
+ y = __atomic_exchange_n(&x, 1, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&x, &y, 0, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
+ __atomic_add_fetch(&x, 1, __ATOMIC_RELAXED);
+ __atomic_sub_fetch(&x, 1, __ATOMIC_RELAXED);
+ __atomic_and_fetch(&x, 0x01, __ATOMIC_RELAXED);
+ __atomic_or_fetch(&x, 0x01, __ATOMIC_RELAXED);
+ __atomic_thread_fence(__ATOMIC_RELAXED);
+ __atomic_signal_fence(__ATOMIC_RELAXED);
+ ])
+ ],[
+ ae_cv_cc_atomic_builtins=yes
+ ],[
+ ae_cv_cc_atomic_builtins=no
+ ])
+ ]
+)
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test "x$ae_cv_cc_atomic_builtins" = "xyes"; then
+ $1
+ :
+else
+ $2
+ :
+fi
+
+AC_LANG_POP
+])dnl AE_CC_ATOMIC_BUILTINS