X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=m4%2Fae_cc_atomic_builtins.m4;fp=m4%2Fae_cc_atomic_builtins.m4;h=2efbde39864293d2fbc8613af29eedb4470b0c18;hp=0000000000000000000000000000000000000000;hb=3afcf5a0407c69b32603a249e8e7b3d309584a85;hpb=c92c99041415698b57ca123e58a19b05189ae398 diff --git a/m4/ae_cc_atomic_builtins.m4 b/m4/ae_cc_atomic_builtins.m4 new file mode 100644 index 0000000..2efbde3 --- /dev/null +++ b/m4/ae_cc_atomic_builtins.m4 @@ -0,0 +1,78 @@ +# SYNOPSIS +# +# AE_CC_ATOMIC_BUILTINS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# LICENSE +# +# Copyright (c) 2023 Michael Jeanson +# +# 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 . +# +# 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