diff --git a/src/iperf.h b/src/iperf.h index 87f787fd5..7b270bd0f 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -77,12 +77,18 @@ #include #endif // HAVE_PTHREAD +/* + * Atomic types highly desired, but if not, we approximate what we need + * with normal integers and warn. + */ #ifdef HAVE_STDATOMIC_H #include +#else +#warning "No available." +typedef uint64_t atomic_uint_fast64_t; #endif // HAVE_STDATOMIC_H #if !defined(__IPERF_API_H) -//typedef uint64_t iperf_size_t; typedef uint_fast64_t iperf_size_t; typedef atomic_uint_fast64_t atomic_iperf_size_t; #endif // __IPERF_API_H diff --git a/src/iperf_api.h b/src/iperf_api.h index fd2ab6bc6..9e70d44f3 100644 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -38,8 +38,15 @@ extern "C" { /* open extern "C" */ #endif +/* + * Atomic types highly desired, but if not, we approximate what we need + * with normal integers and warn. + */ #ifdef HAVE_STDATOMIC_H #include +#else +#warning "No available" +typedef u_int64_t atomic_uint_fast64_t; #endif // HAVE_STDATOMIC_H struct iperf_test; diff --git a/src/main.c b/src/main.c index 3b397c00a..b179f5bde 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* - * iperf, Copyright (c) 2014-2022, The Regents of the University of + * iperf, Copyright (c) 2014-2023, The Regents of the University of * California, through Lawrence Berkeley National Laboratory (subject * to receipt of any required approvals from the U.S. Dept. of * Energy). All rights reserved. @@ -59,6 +59,24 @@ main(int argc, char **argv) { struct iperf_test *test; + /* + * Atomics check. We prefer to have atomic types (which is + * basically on any compiler supporting C11 or better). If we + * don't have them, we try to approximate the type we need with a + * regular integer, but complain if they're not lock-free. We only + * know how to check this on GCC. GCC on CentOS 7 / RHEL 7 is the + * targeted use case for these check. + */ +#ifndef HAVE_STDATOMIC_H +#ifdef __GNUC__ + if (! __atomic_always_lock_free (sizeof (u_int64_t), 0)) { +#endif // __GNUC__ + fprintf(stderr, "Warning: Cannot guarantee lock-free operation with 64-bit data types\n"); +#ifdef __GNUC__ + } +#endif // __GNUC__ +#endif // HAVE_STDATOMIC_H + // XXX: Setting the process affinity requires root on most systems. // Is this a feature we really need? #ifdef TEST_PROC_AFFINITY