From dc91bed46dd12fdc843b9e2c4ed9f3e570914ba3 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 8 Dec 2021 12:01:32 -0500 Subject: Could use GCC atomics for older versions of GCC. This should help greatly with performance on older systems such as CentOS 7 and GCC 4.8. Though, such folks really should update to newer compilers. Folks running version of GCC earlier than 4.7 will still pay a rather significant performance penalty, as they still implement atomics with a global mutex. --- src/platform/posix/posix_impl.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/platform/posix/posix_impl.h') diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index 0ee7cb38..afbdce97 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -58,13 +58,19 @@ struct nni_plat_mtx { pthread_mutex_t mtx; }; -#define NNI_MTX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } +#define NNI_MTX_INITIALIZER \ + { \ + PTHREAD_MUTEX_INITIALIZER \ + } struct nni_rwlock { pthread_rwlock_t rwl; }; -#define NNI_RWLOCK_INITIALIZER { PTHREAD_RWLOCK_INITIALIZER } +#define NNI_RWLOCK_INITIALIZER \ + { \ + PTHREAD_RWLOCK_INITIALIZER \ + } // No static form of CV initialization because of the need to use // attributes to set the clock type. @@ -76,7 +82,10 @@ struct nni_plat_cv { // NOTE: condition variables initialized with this should *NOT* // be used with nni_cv_until -- the clock attributes are not passed // and the wake-up times will not be correct. -#define NNI_CV_INITIALIZER(mxp) { .mtx = mxp, .cv = PTHREAD_COND_INITIALIZER } +#define NNI_CV_INITIALIZER(mxp) \ + { \ + .mtx = mxp, .cv = PTHREAD_COND_INITIALIZER \ + } struct nni_plat_thr { pthread_t tid; @@ -91,7 +100,6 @@ struct nni_plat_flock { #define NNG_PLATFORM_DIR_SEP "/" #ifdef NNG_HAVE_STDATOMIC - #include struct nni_atomic_flag { -- cgit v1.2.3-70-g09d2