aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends/sndio.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-02-04 00:01:12 -0800
committerChris Robinson <[email protected]>2018-02-04 00:01:12 -0800
commit9b878c64f9ec83adc4886db553ca184952ff50b4 (patch)
treedb4df8b93f71ac2f0887d803f98314d8994011ea /Alc/backends/sndio.c
parent1f61472e77faa0b57231b19236272d3e4d67fbc0 (diff)
Make the Connected state atomic
Also don't send the Disconnected event more than once.
Diffstat (limited to 'Alc/backends/sndio.c')
-rw-r--r--Alc/backends/sndio.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/Alc/backends/sndio.c b/Alc/backends/sndio.c
index 06a434d9..5aea457b 100644
--- a/Alc/backends/sndio.c
+++ b/Alc/backends/sndio.c
@@ -43,7 +43,7 @@ typedef struct ALCsndioBackend {
ALvoid *mix_data;
ALsizei data_size;
- volatile int killNow;
+ ATOMIC(int) killNow;
althrd_t thread;
} ALCsndioBackend;
@@ -75,6 +75,7 @@ static void ALCsndioBackend_Construct(ALCsndioBackend *self, ALCdevice *device)
self->sndHandle = NULL;
self->mix_data = NULL;
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
}
static void ALCsndioBackend_Destruct(ALCsndioBackend *self)
@@ -102,7 +103,8 @@ static int ALCsndioBackend_mixerProc(void *ptr)
frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
- while(!self->killNow && device->Connected)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
ALsizei len = self->data_size;
ALubyte *WritePtr = self->mix_data;
@@ -110,7 +112,7 @@ static int ALCsndioBackend_mixerProc(void *ptr)
ALCsndioBackend_lock(self);
aluMixData(device, WritePtr, len/frameSize);
ALCsndioBackend_unlock(self);
- while(len > 0 && !self->killNow)
+ while(len > 0 && !ATOMIC_LOAD(&self->killNow, almemory_order_acquire))
{
wrote = sio_write(self->sndHandle, WritePtr, len);
if(wrote == 0)
@@ -253,7 +255,7 @@ static ALCboolean ALCsndioBackend_start(ALCsndioBackend *self)
return ALC_FALSE;
}
- self->killNow = 0;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, ALCsndioBackend_mixerProc, self) != althrd_success)
{
sio_stop(self->sndHandle);
@@ -267,10 +269,8 @@ static void ALCsndioBackend_stop(ALCsndioBackend *self)
{
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);
if(!sio_stop(self->sndHandle))