mac: use atomic_thread_fence() to avoid deprecation (#663)

OSMemoryBarrier() is deprecated and causes build failures
when "-Wall -Werror" are used.

Use memory_order_seq_cst for full barrier
Use CMake C_STANDARD 11

Fixes #639
This commit is contained in:
Phil Burk 2021-12-01 18:25:04 -07:00 committed by GitHub
parent 438447ffe5
commit b94c49ee21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -284,6 +284,10 @@ elseif(UNIX)
)
target_compile_definitions(PortAudio PUBLIC PA_USE_COREAUDIO=1)
set(PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS} -DPA_USE_COREAUDIO=1")
# Use C11 so that we can make use of atomic library and avoid deprecation errors.
set_property(TARGET PortAudio PROPERTY C_STANDARD 11)
set(PKGCONFIG_LDFLAGS_PRIVATE
"${PKGCONFIG_LDFLAGS_PRIVATE} -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework CoreFoundation -framework CoreServices")
else()

View File

@ -61,13 +61,23 @@
****************/
#if defined(__APPLE__)
# include <libkern/OSAtomic.h>
/* Here are the memory barrier functions. Mac OS X only provides
full memory barriers, so the three types of barriers are the same,
however, these barriers are superior to compiler-based ones. */
# define PaUtil_FullMemoryBarrier() OSMemoryBarrier()
# define PaUtil_ReadMemoryBarrier() OSMemoryBarrier()
# define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
/* Support for the atomic library was added in C11.
*/
# if (__STDC_VERSION__ < 201112L) || defined(__STDC_NO_ATOMICS__)
# include <libkern/OSAtomic.h>
/* Here are the memory barrier functions. Mac OS X only provides
full memory barriers, so the three types of barriers are the same,
however, these barriers are superior to compiler-based ones.
These were deprecated in MacOS 10.12. */
# define PaUtil_FullMemoryBarrier() OSMemoryBarrier()
# define PaUtil_ReadMemoryBarrier() OSMemoryBarrier()
# define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
# else
# include <stdatomic.h>
# define PaUtil_FullMemoryBarrier() atomic_thread_fence(memory_order_seq_cst)
# define PaUtil_ReadMemoryBarrier() atomic_thread_fence(memory_order_acquire)
# define PaUtil_WriteMemoryBarrier() atomic_thread_fence(memory_order_release)
# endif
#elif defined(__GNUC__)
/* GCC >= 4.1 has built-in intrinsics. We'll use those */
# if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)