summaryrefslogtreecommitdiffstats
path: root/wscript
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-05-21 01:04:47 +0200
committerwm4 <wm4@nowhere>2014-05-21 02:21:18 +0200
commit8e7cf4bc992f13dbb523bb42d6b9de4bc2f486c2 (patch)
tree77f21515a336c368d2bb97eab11d950bed9f5c4d /wscript
parent2f65f0e2548f95b3b8ba6620efe6c0e3cb02420b (diff)
downloadmpv-8e7cf4bc992f13dbb523bb42d6b9de4bc2f486c2.tar.bz2
mpv-8e7cf4bc992f13dbb523bb42d6b9de4bc2f486c2.tar.xz
atomics: switch to C11 stdatomic.h
In my opinion, we shouldn't use atomics at all, but ok. This switches the mpv code to use C11 stdatomic.h, and for compilers that don't support stdatomic.h yet, we emulate the subset used by mpv using the builtins commonly provided by gcc and clang. This supersedes an earlier similar attempt by Kovensky. That attempt unfortunately relied on a big copypasted freebsd header (which also depended on much more highly compiler-specific functionality, defined reserved symbols, etc.), so it had to be NIH'ed. Some issues: - C11 says default initialization of atomics "produces a valid state", but it's not sure whether the stored value is really 0. But we rely on this. - I'm pretty sure our use of the __atomic... builtins is/was incorrect. We don't use atomic load/store intrinsics, and access stuff directly. - Our wrapper actually does stricter typechecking than the stdatomic.h implementation by gcc 4.9. We make the atomic types incompatible with normal types by wrapping them into structs. (The FreeBSD wrapper does the same.) - I couldn't test on MinGW.
Diffstat (limited to 'wscript')
-rw-r--r--wscript14
1 files changed, 11 insertions, 3 deletions
diff --git a/wscript b/wscript
index 796c0819bf..be900c03f7 100644
--- a/wscript
+++ b/wscript
@@ -105,24 +105,32 @@ main_dependencies = [
'req': True,
'fmsg': 'Unable to find pthreads support.'
}, {
+ 'name': 'stdatomic',
+ 'desc': 'stdatomic.h',
+ 'func':
+ check_statement('stdatomic.h',
+ '_Atomic int test = ATOMIC_VAR_INIT(123);'
+ 'int test2 = atomic_load(&test)')
+ }, {
'name': 'atomic-builtins',
'desc': 'compiler support for __atomic built-ins',
'func': check_libs(['atomic'],
check_statement('stdint.h',
'int64_t test = 0;'
- 'test = __atomic_add_fetch(&test, 1, __ATOMIC_SEQ_CST)'))
+ 'test = __atomic_add_fetch(&test, 1, __ATOMIC_SEQ_CST)')),
+ 'deps_neg': [ 'stdatomic' ],
}, {
'name': 'sync-builtins',
'desc': 'compiler support for __sync built-ins',
'func': check_statement('stdint.h',
'int64_t test = 0;'
'test = __sync_add_and_fetch(&test, 1)'),
- 'deps_neg': [ 'atomic-builtins' ],
+ 'deps_neg': [ 'stdatomic', 'atomic-builtins' ],
}, {
'name': 'thread-synchronization-builtins',
'desc': 'compiler support for usable thread synchronization built-ins',
'func': check_true,
- 'deps_any': ['atomic-builtins', 'sync-builtins'],
+ 'deps_any': ['stdatomic', 'atomic-builtins', 'sync-builtins'],
'req': True,
'fmsg': 'your compiler must support either __atomic or __sync built-ins',
}, {