Commit 1e996445 authored by Arun Raghavan's avatar Arun Raghavan

build-sys: meson: Add atomic ops related checks

parent 25308fe8
......@@ -371,12 +371,23 @@ size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, si
endif
endif
# Atomic operations
if get_option('atomic-arm-memory-barrier')
cdata.set('ATOMIC_ARM_MEMORY_BARRIER_ENABLED', 1)
endif
need_libatomic_ops = false
atomictest = '''void func() {
volatile int atomic = 2;
__sync_bool_compare_and_swap (&atomic, 2, 3);
}
'''
if cc.compiles(atomictest)
cdata.set('HAVE_ATOMIC_BUILTINS', 1)
newatomictest = '''void func() {
int c = 0;
__atomic_store_n(&c, 4, __ATOMIC_SEQ_CST);
......@@ -384,12 +395,48 @@ if cc.compiles(atomictest)
'''
if(cc.compiles(newatomictest))
cdata.set('HAVE_ATOMIC_BUILTINS_MEMORY_MODEL', true)
cdata.set('HAVE_ATOMIC_BUILTINS_MEMORY_MODEL', 1)
endif
cdata.set('HAVE_ATOMIC_BUILTINS', true)
elif host_machine.cpu_family() == 'arm'
if host_machine.system() == 'linux' and get_option('atomic-arm-linux-helpers')
cdata.set('ATOMIC_ARM_LINUX_HELPERS', 1)
else
armatomictest = '''void func() {
volatile int a=0;
int o=0, n=1, r;
asm volatile ("ldrex %0, [%1]\n"
"subs %0, %0, %2\n"
"strexeq %0, %3, [%1]\n"
: "=&r" (r)
: "r" (&a), "Ir" (o), "r" (n)
: "cc");
return (a==1 ? 0 : -1);
'''
if cc.compiles(aratomictest)
cdata.set('ATOMIC_ARM_INLINE_ASM', 1)
else
need_libatomic_ops = true
endif
endif # arm && !linux
elif not ['freebsd', 'netbsd'].contains(host_machine.system())
need_libatomic_ops = true
endif # !atomic helpers && !arm
if need_libatomic_ops
assert(cc.has_header('atomic_ops.h'), 'Need libatomic_ops')
cdata.set('AO_REQUIRE_CAS', 1)
if host_machine.system() != 'windows'
libatomic_ops_dep = cc.find_library('atomic_ops', required : true)
else
libatomic_ops_dep = dependency('', required: false)
endif
else
# FIXME: check if we need libatomic_ops
libatomic_ops_dep = dependency('', required: false)
endif
# FIXME: make sure it's >= 2.2
......
......@@ -27,6 +27,12 @@ option('legacy-database-entry-format',
option('running-from-build-tree',
type : 'boolean',
description : 'Enable running from build tree')
option('atomic-arm-linux-helpers',
type : 'boolean', value : true,
description : 'Use inline asm or libatomic_ops instead')
option('atomic-arm-memory-barrier',
type : 'boolean', value : false,
description : 'Enable memory barriers (only really needed in SMP arm systems)')
# Paths
......
......@@ -32,7 +32,7 @@ libalsa_util = shared_library('alsa-util',
c_args : [pa_c_args, server_c_args],
link_args : [nodelete_link_args],
include_directories : [configinc, topinc],
dependencies : [libpulse_dep, libpulsecommon_dep, libpulsecore_dep, alsa_dep, dbus_dep, libm_dep, udev_dep],
dependencies : [libpulse_dep, libpulsecommon_dep, libpulsecore_dep, alsa_dep, dbus_dep, libatomic_ops_dep, libm_dep, udev_dep],
install : true,
install_rpath : privlibdir,
install_dir : modlibexecdir,
......
......@@ -14,7 +14,7 @@ libwebrtc_util = shared_library('webrtc-util',
libwebrtc_util_sources,
cpp_args : [pa_c_args, server_c_args],
include_directories : [configinc, topinc],
dependencies : [libpulse_dep, libpulsecommon_dep, libpulsecore_dep, webrtc_dep],
dependencies : [libpulse_dep, libpulsecommon_dep, libpulsecore_dep, libatomic_ops_dep, webrtc_dep],
link_args : [nodelete_link_args, '-Wl,--unresolved-symbols=ignore-in-object-files'],
install : true,
install_rpath : privlibdir,
......
......@@ -20,7 +20,7 @@ librtp = shared_library('rtp',
c_args : [pa_c_args, server_c_args],
link_args : [nodelete_link_args],
include_directories : [configinc, topinc],
dependencies : [libpulse_dep, libpulsecommon_dep, libpulsecore_dep],
dependencies : [libpulse_dep, libpulsecommon_dep, libpulsecore_dep, libatomic_ops_dep],
install : true,
install_rpath : privlibdir,
install_dir : modlibexecdir,
......
......@@ -198,7 +198,7 @@ libpulsecore = shared_library('pulsecore-' + pa_version_major_minor,
install_rpath : privlibdir,
install_dir : privlibdir,
link_with : libpulsecore_simd_lib,
dependencies : [libm_dep, libpulsecommon_dep, libpulse_dep, ltdl_dep, shm_dep, sndfile_dep, database_dep, dbus_dep, orc_dep, samplerate_dep, soxr_dep, speex_dep, x11_dep],
dependencies : [libm_dep, libpulsecommon_dep, libpulse_dep, ltdl_dep, shm_dep, sndfile_dep, database_dep, dbus_dep, libatomic_ops_dep, orc_dep, samplerate_dep, soxr_dep, speex_dep, x11_dep],
implicit_include_directories : false)
libpulsecore_dep = declare_dependency(link_with: libpulsecore)
......
......@@ -82,7 +82,7 @@ endif
if host_machine.system() != 'darwin'
default_tests += [
[ 'once-test', 'once-test.c',
[ check_dep, thread_dep, libpulse_dep, libpulsecommon_dep, libpulsecore_dep ] ],
[ check_dep, thread_dep, libpulse_dep, libpulsecommon_dep, libpulsecore_dep, libatomic_ops_dep ] ],
]
endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment