summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_wasapi.c
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 /audio/out/ao_wasapi.c
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 'audio/out/ao_wasapi.c')
-rw-r--r--audio/out/ao_wasapi.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c
index 3d59554dcd..431b24c3a1 100644
--- a/audio/out/ao_wasapi.c
+++ b/audio/out/ao_wasapi.c
@@ -33,7 +33,6 @@
#include "audio/out/ao_wasapi_utils.h"
#include "audio/format.h"
-#include "compat/atomics.h"
#include "osdep/timer.h"
#include "osdep/io.h"
@@ -43,7 +42,7 @@
do { if ((unk) != NULL) { release; (unk) = NULL; } } while(0)
static double get_device_delay(struct wasapi_state *state) {
- UINT64 sample_count = state->sample_count;
+ UINT64 sample_count = atomic_load(&state->sample_count);
UINT64 position, qpc_position;
HRESULT hr;
@@ -100,8 +99,7 @@ static void thread_feed(struct ao *ao)
frame_count, 0);
EXIT_ON_ERROR(hr);
- mp_atomic_add_and_fetch(&state->sample_count, frame_count);
- mp_memory_barrier();
+ atomic_fetch_add(&state->sample_count, frame_count);
return;
exit_label:
@@ -318,8 +316,7 @@ static void audio_pause(struct ao *ao)
IAudioClient_Stop(state->pAudioClientProxy);
IAudioClient_Reset(state->pAudioClientProxy);
- state->sample_count = 0;
- mp_memory_barrier();
+ atomic_store(&state->sample_count, 0);
}
static void audio_resume(struct ao *ao)