From 206330116c2327824adb1f70d16d3f090b5a1ad3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 16 Dec 2017 08:34:17 +0100 Subject: Use C11 memory barriers where available --- src/zix/ring.c | 24 ++++++++++++++---------- wscript | 3 +++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/zix/ring.c b/src/zix/ring.c index 3da4f7f..c5b41f5 100644 --- a/src/zix/ring.c +++ b/src/zix/ring.c @@ -1,5 +1,5 @@ /* - Copyright 2011 David Robillard + Copyright 2011-2017 David Robillard Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -29,23 +29,27 @@ # define ZIX_MLOCK(ptr, size) #endif -#if defined(__APPLE__) +#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) +# include +# define ZIX_WRITE_BARRIER() atomic_thread_fence(memory_order_release) +# define ZIX_READ_BARRIER() atomic_thread_fence(memory_order_acquire) +#elif defined(__APPLE__) /* Pre 10.12 */ # include -# define ZIX_FULL_BARRIER() OSMemoryBarrier() +# define ZIX_WRITE_BARRIER() OSMemoryBarrier() +# define ZIX_READ_BARRIER() OSMemoryBarrier() #elif defined(_WIN32) # include -# define ZIX_FULL_BARRIER() MemoryBarrier() +# define ZIX_WRITE_BARRIER() MemoryBarrier() +# define ZIX_READ_BARRIER() MemoryBarrier() #elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) -# define ZIX_FULL_BARRIER() __sync_synchronize() +# define ZIX_WRITE_BARRIER() __sync_synchronize() +# define ZIX_READ_BARRIER() __sync_synchronize() #else # pragma message("warning: No memory barriers, possible SMP bugs") -# define ZIX_FULL_BARRIER() +# define ZIX_WRITE_BARRIER() +# define ZIX_READ_BARRIER() #endif -/* No support for any systems with separate read and write barriers */ -#define ZIX_READ_BARRIER() ZIX_FULL_BARRIER() -#define ZIX_WRITE_BARRIER() ZIX_FULL_BARRIER() - #include "zix/ring.h" struct ZixRingImpl { diff --git a/wscript b/wscript index e2adc63..f65055d 100644 --- a/wscript +++ b/wscript @@ -51,6 +51,9 @@ def configure(conf): autowaf.set_c99_mode(conf) autowaf.set_cxx11_mode(conf) + if conf.check(cflags=["-std=c11"]): + conf.env.append_unique('CFLAGS', ['-std=c11']) + autowaf.check_pkg(conf, 'lv2', atleast_version='1.14.0', uselib_store='LV2') autowaf.check_pkg(conf, 'lilv-0', uselib_store='LILV', atleast_version='0.24.0', mandatory=True) -- cgit v1.2.1