build: always require atomics

Always require them, instead of just for some components which have hard
requirements on correct atomic semantics. They should be widely
available, and are supported by all recent gcc and clang compiler
versions. We even have the fallbacks builtins, which should keep this
working on very old gcc releases.

In particular, w32_common.c recently added a hard requirement on
atomics, but checking this properly in the build system would have been
messy. This commit makes sure it always works.

The fallback where weak atomic semantics are always fine is in theory
rather questionable as well.
This commit is contained in:
wm4 2016-08-05 17:10:22 +02:00
parent b2e5eb13bc
commit d4ee5e5a8a
2 changed files with 10 additions and 26 deletions

View File

@ -28,15 +28,14 @@
// Emulate the parts of C11 stdatomic.h needed by mpv.
// Still relies on gcc/clang atomic builtins.
// The t field is a hack to make the non-atomic fallback macro mess work.
typedef struct { volatile unsigned long v, t; } atomic_ulong;
typedef struct { volatile int v, t; } atomic_int;
typedef struct { volatile unsigned int v, t; } atomic_uint;
typedef struct { volatile _Bool v, t; } atomic_bool;
typedef struct { volatile long long v, t; } atomic_llong;
typedef struct { volatile uint_least32_t v, t; } atomic_uint_least32_t;
typedef struct { volatile unsigned long long v, t; } atomic_ullong;
typedef struct { volatile unsigned long v; } atomic_ulong;
typedef struct { volatile int v; } atomic_int;
typedef struct { volatile unsigned int v; } atomic_uint;
typedef struct { volatile _Bool v; } atomic_bool;
typedef struct { volatile long long v; } atomic_llong;
typedef struct { volatile uint_least32_t v; } atomic_uint_least32_t;
typedef struct { volatile unsigned long long v; } atomic_ullong;
#define ATOMIC_VAR_INIT(x) \
{.v = (x)}
@ -82,19 +81,7 @@ typedef struct { volatile unsigned long long v, t; } atomic_ullong;
ok_; })
#else
// This is extremely wrong. The build system actually disables code that has
// a serious dependency on working atomics, so this is barely ok.
#define atomic_load(p) ((p)->v)
#define atomic_store(p, val) ((p)->v = (val))
#define atomic_fetch_op_(a, b, op) \
((a)->t = (a)->v, (a)->v = (a)->v op (b), (a)->t)
#define atomic_fetch_add(a, b) atomic_fetch_op_(a, b, +)
#define atomic_fetch_and(a, b) atomic_fetch_op_(a, b, &)
#define atomic_fetch_or(a, b) atomic_fetch_op_(a, b, |)
#define atomic_compare_exchange_strong(p, old, new) \
((p)->v == *(old) ? ((p)->v = (new), 1) : (*(old) = (p)->v, 0))
# error "this should have been a configuration error, report a bug please"
#endif /* no atomics */
#endif /* else HAVE_STDATOMIC */

View File

@ -175,6 +175,7 @@ main_dependencies = [
'name': 'atomics',
'desc': 'compiler support for usable thread synchronization built-ins',
'func': check_true,
'req': True,
'deps_any': ['stdatomic', 'atomic-builtins', 'sync-builtins'],
}, {
'name': 'c11-tls',
@ -517,13 +518,11 @@ audio_output_features = [
{
'name': '--sdl2',
'desc': 'SDL2',
'deps': ['atomics'],
'func': check_pkg_config('sdl2'),
'default': 'disable'
}, {
'name': '--sdl1',
'desc': 'SDL (1.x)',
'deps': ['atomics'],
'deps_neg': [ 'sdl2' ],
'func': check_pkg_config('sdl'),
'default': 'disable'
@ -574,7 +573,6 @@ audio_output_features = [
}, {
'name': '--jack',
'desc': 'JACK audio output',
'deps': ['atomics'],
'func': check_pkg_config('jack'),
}, {
'name': '--openal',
@ -592,14 +590,13 @@ audio_output_features = [
}, {
'name': '--coreaudio',
'desc': 'CoreAudio audio output',
'deps': ['atomics'],
'func': check_cc(
fragment=load_fragment('coreaudio.c'),
framework_name=['CoreFoundation', 'CoreAudio', 'AudioUnit', 'AudioToolbox'])
}, {
'name': '--wasapi',
'desc': 'WASAPI audio output',
'deps': ['win32', 'atomics'],
'deps': ['win32'],
'func': check_cc(fragment=load_fragment('wasapi.c')),
}
]