diff options
author | Chris Robinson <[email protected]> | 2018-02-04 00:01:12 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-02-04 00:01:12 -0800 |
commit | 9b878c64f9ec83adc4886db553ca184952ff50b4 (patch) | |
tree | db4df8b93f71ac2f0887d803f98314d8994011ea /Alc/backends/wave.c | |
parent | 1f61472e77faa0b57231b19236272d3e4d67fbc0 (diff) |
Make the Connected state atomic
Also don't send the Disconnected event more than once.
Diffstat (limited to 'Alc/backends/wave.c')
-rw-r--r-- | Alc/backends/wave.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c index 13ffaeec..557c2bf2 100644 --- a/Alc/backends/wave.c +++ b/Alc/backends/wave.c @@ -77,7 +77,7 @@ typedef struct ALCwaveBackend { ALvoid *mBuffer; ALuint mSize; - volatile int killNow; + ATOMIC(ALenum) killNow; althrd_t thread; } ALCwaveBackend; @@ -110,7 +110,7 @@ static void ALCwaveBackend_Construct(ALCwaveBackend *self, ALCdevice *device) self->mBuffer = NULL; self->mSize = 0; - self->killNow = 1; + ATOMIC_INIT(&self->killNow, AL_TRUE); } static void ALCwaveBackend_Destruct(ALCwaveBackend *self) @@ -143,7 +143,8 @@ static int ALCwaveBackend_mixerProc(void *ptr) ERR("Failed to get starting time\n"); return 1; } - while(!self->killNow && device->Connected) + while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) && + ATOMIC_LOAD(&device->Connected, almemory_order_acquire)) { if(altimespec_get(&now, AL_TIME_UTC) != AL_TIME_UTC) { @@ -355,7 +356,7 @@ static ALCboolean ALCwaveBackend_start(ALCwaveBackend *self) return ALC_FALSE; } - self->killNow = 0; + ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release); if(althrd_create(&self->thread, ALCwaveBackend_mixerProc, self) != althrd_success) { free(self->mBuffer); @@ -373,10 +374,8 @@ static void ALCwaveBackend_stop(ALCwaveBackend *self) long size; int res; - if(self->killNow) + if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel)) return; - - self->killNow = 1; althrd_join(self->thread, &res); free(self->mBuffer); |