aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/backends/jack.cpp33
-rw-r--r--Alc/backends/opensl.cpp31
2 files changed, 35 insertions, 29 deletions
diff --git a/Alc/backends/jack.cpp b/Alc/backends/jack.cpp
index fc385f7b..0862f685 100644
--- a/Alc/backends/jack.cpp
+++ b/Alc/backends/jack.cpp
@@ -26,6 +26,8 @@
#include <stdio.h>
#include <memory.h>
+#include <thread>
+
#include "alMain.h"
#include "alu.h"
#include "alconfig.h"
@@ -152,13 +154,13 @@ struct ALCjackPlayback final : public ALCbackend {
alsem_t Sem;
std::atomic<ALenum> mKillNow{AL_TRUE};
- althrd_t thread;
+ std::thread mThread;
};
static int ALCjackPlayback_bufferSizeNotify(jack_nframes_t numframes, void *arg);
static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg);
-static int ALCjackPlayback_mixerProc(void *arg);
+static int ALCjackPlayback_mixerProc(ALCjackPlayback *self);
static void ALCjackPlayback_Construct(ALCjackPlayback *self, ALCdevice *device);
static void ALCjackPlayback_Destruct(ALCjackPlayback *self);
@@ -291,9 +293,8 @@ static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg)
return 0;
}
-static int ALCjackPlayback_mixerProc(void *arg)
+static int ALCjackPlayback_mixerProc(ALCjackPlayback *self)
{
- ALCjackPlayback *self = static_cast<ALCjackPlayback*>(arg);
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
SetRTPriority();
@@ -465,25 +466,27 @@ static ALCboolean ALCjackPlayback_start(ALCjackPlayback *self)
}
jack_free(ports);
- self->mKillNow.store(AL_FALSE, std::memory_order_release);
- if(althrd_create(&self->thread, ALCjackPlayback_mixerProc, self) != althrd_success)
- {
- jack_deactivate(self->Client);
- return ALC_FALSE;
+ try {
+ self->mKillNow.store(AL_FALSE, std::memory_order_release);
+ self->mThread = std::thread(ALCjackPlayback_mixerProc, self);
+ return ALC_TRUE;
}
-
- return ALC_TRUE;
+ catch(std::exception& e) {
+ ERR("Could not create playback thread: %s\n", e.what());
+ }
+ catch(...) {
+ }
+ jack_deactivate(self->Client);
+ return ALC_FALSE;
}
static void ALCjackPlayback_stop(ALCjackPlayback *self)
{
- int res;
-
- if(self->mKillNow.exchange(AL_TRUE, std::memory_order_acq_rel))
+ if(self->mKillNow.exchange(AL_TRUE, std::memory_order_acq_rel) || !self->mThread.joinable())
return;
alsem_post(&self->Sem);
- althrd_join(self->thread, &res);
+ self->mThread.join();
jack_deactivate(self->Client);
}
diff --git a/Alc/backends/opensl.cpp b/Alc/backends/opensl.cpp
index 9e8e5031..8cea36f3 100644
--- a/Alc/backends/opensl.cpp
+++ b/Alc/backends/opensl.cpp
@@ -26,6 +26,8 @@
#include <stdlib.h>
#include <jni.h>
+#include <thread>
+
#include "alMain.h"
#include "alu.h"
#include "ringbuffer.h"
@@ -149,11 +151,11 @@ struct ALCopenslPlayback final : public ALCbackend {
ALsizei mFrameSize{0};
std::atomic<ALenum> mKillNow{AL_TRUE};
- althrd_t mThread;
+ std::thread mThread;
};
static void ALCopenslPlayback_process(SLAndroidSimpleBufferQueueItf bq, void *context);
-static int ALCopenslPlayback_mixerProc(void *arg);
+static int ALCopenslPlayback_mixerProc(ALCopenslPlayback *self);
static void ALCopenslPlayback_Construct(ALCopenslPlayback *self, ALCdevice *device);
static void ALCopenslPlayback_Destruct(ALCopenslPlayback *self);
@@ -224,9 +226,8 @@ static void ALCopenslPlayback_process(SLAndroidSimpleBufferQueueItf UNUSED(bq),
}
-static int ALCopenslPlayback_mixerProc(void *arg)
+static int ALCopenslPlayback_mixerProc(ALCopenslPlayback *self)
{
- ALCopenslPlayback *self = static_cast<ALCopenslPlayback*>(arg);
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
SLAndroidSimpleBufferQueueItf bufferQueue;
SLPlayItf player;
@@ -580,14 +581,17 @@ static ALCboolean ALCopenslPlayback_start(ALCopenslPlayback *self)
if(SL_RESULT_SUCCESS != result)
return ALC_FALSE;
- self->mKillNow.store(AL_FALSE);
- if(althrd_create(&self->mThread, ALCopenslPlayback_mixerProc, self) != althrd_success)
- {
- ERR("Failed to start mixer thread\n");
- return ALC_FALSE;
+ try {
+ self->mKillNow.store(AL_FALSE);
+ self->mThread = std::thread(ALCopenslPlayback_mixerProc, self);
+ return ALC_TRUE;
}
-
- return ALC_TRUE;
+ catch(std::exception& e) {
+ ERR("Could not create playback thread: %s\n", e.what());
+ }
+ catch(...) {
+ }
+ return ALC_FALSE;
}
@@ -596,13 +600,12 @@ static void ALCopenslPlayback_stop(ALCopenslPlayback *self)
SLAndroidSimpleBufferQueueItf bufferQueue;
SLPlayItf player;
SLresult result;
- int res;
- if(self->mKillNow.exchange(AL_TRUE))
+ if(self->mKillNow.exchange(AL_TRUE) || !self->mThread.joinable())
return;
alsem_post(&self->mSem);
- althrd_join(self->mThread, &res);
+ self->mThread.join();
result = VCALL(self->mBufferQueueObj,GetInterface)(SL_IID_PLAY, &player);
PRINTERR(result, "bufferQueue->GetInterface");