summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <arun@arunraghavan.net>2019-08-15 13:07:54 +0530
committerArun Raghavan <arun@arunraghavan.net>2019-08-15 18:57:13 +0530
commit1e996445f75f0984126572fb1548a6f5afac6c2f (patch)
treeea36dd4fa3666859d691f78ae0a4a377784fe042
parent25308fe88f83bed2f4554bdaf6cefa8e18100c3f (diff)
build-sys: meson: Add atomic ops related checks
-rw-r--r--meson.build53
-rw-r--r--meson_options.txt6
-rw-r--r--src/modules/alsa/meson.build2
-rw-r--r--src/modules/echo-cancel/meson.build2
-rw-r--r--src/modules/rtp/meson.build2
-rw-r--r--src/pulsecore/meson.build2
-rw-r--r--src/tests/meson.build2
7 files changed, 61 insertions, 8 deletions
diff --git a/meson.build b/meson.build
index 7906b1dd0..4d5fc58b3 100644
--- a/meson.build
+++ b/meson.build
@@ -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
diff --git a/meson_options.txt b/meson_options.txt
index 09873ddd2..766877319 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -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
diff --git a/src/modules/alsa/meson.build b/src/modules/alsa/meson.build
index d8d46fa46..5309dc108 100644
--- a/src/modules/alsa/meson.build
+++ b/src/modules/alsa/meson.build
@@ -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,
diff --git a/src/modules/echo-cancel/meson.build b/src/modules/echo-cancel/meson.build
index cdb53d66a..171a41482 100644
--- a/src/modules/echo-cancel/meson.build
+++ b/src/modules/echo-cancel/meson.build
@@ -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,
diff --git a/src/modules/rtp/meson.build b/src/modules/rtp/meson.build
index 29ab195fd..c3efde6ab 100644
--- a/src/modules/rtp/meson.build
+++ b/src/modules/rtp/meson.build
@@ -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,
diff --git a/src/pulsecore/meson.build b/src/pulsecore/meson.build
index b595e7705..19f6b9e99 100644
--- a/src/pulsecore/meson.build
+++ b/src/pulsecore/meson.build
@@ -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)
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 15286f579..d68fbd0e3 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -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