aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-26 21:19:20 -0800
committerChris Robinson <[email protected]>2018-11-26 21:39:31 -0800
commitb108d0acfd062756da69074242e24ea7b2856b8a (patch)
tree40a573fbefeb77310f375ace284bc847b4014973 /Alc
parent7860a11ae2723d744eb35eae9bbbc6f9a55e9caa (diff)
Remove the last remaining uses of althrd_t
Diffstat (limited to 'Alc')
-rw-r--r--Alc/backends/qsa.cpp24
-rw-r--r--Alc/backends/sndio.cpp64
-rw-r--r--Alc/backends/solaris.cpp30
3 files changed, 67 insertions, 51 deletions
diff --git a/Alc/backends/qsa.cpp b/Alc/backends/qsa.cpp
index b40b5b6b..3d09a744 100644
--- a/Alc/backends/qsa.cpp
+++ b/Alc/backends/qsa.cpp
@@ -28,6 +28,7 @@
#include <errno.h>
#include <memory.h>
+#include <thread>
#include <memory>
#include <algorithm>
@@ -53,7 +54,7 @@ struct qsa_data {
ALsizei size{0};
std::atomic<ALenum> mKillNow{AL_TRUE};
- althrd_t thread;
+ std::thread mThread;
};
struct DevMap {
@@ -592,21 +593,26 @@ static ALCboolean qsa_start_playback(PlaybackWrapper *self)
{
qsa_data *data = self->ExtraData.get();
- data->mKillNow.store(AL_FALSE, std::memory_order_release);
- if(althrd_create(&data->thread, qsa_proc_playback, self) != althrd_success)
- return ALC_FALSE;
-
- return ALC_TRUE;
+ try {
+ data->mKillNow.store(AL_FALSE, std::memory_order_release);
+ data->mThread = std::thread(qsa_proc_playback, self);
+ return ALC_TRUE;
+ }
+ catch(std::exception& e) {
+ ERR("Could not create playback thread: %s\n", e.what());
+ }
+ catch(...) {
+ }
+ return ALC_FALSE;
}
static void qsa_stop_playback(PlaybackWrapper *self)
{
qsa_data *data = self->ExtraData.get();
- int res;
- if(data->mKillNow.exchange(AL_TRUE, std::memory_order_acq_rel))
+ if(data->mKillNow.exchange(AL_TRUE, std::memory_order_acq_rel) || !data->mThread.joinable())
return;
- althrd_join(data->thread, &res);
+ data->mThread.join();
}
diff --git a/Alc/backends/sndio.cpp b/Alc/backends/sndio.cpp
index 2a999bd4..1dabe5ca 100644
--- a/Alc/backends/sndio.cpp
+++ b/Alc/backends/sndio.cpp
@@ -26,6 +26,8 @@
#include <stdlib.h>
#include <string.h>
+#include <thread>
+
#include "alMain.h"
#include "alu.h"
#include "threads.h"
@@ -44,10 +46,10 @@ struct SndioPlayback final : public ALCbackend {
ALsizei data_size{0};
std::atomic<ALenum> mKillNow{AL_TRUE};
- althrd_t thread;
+ std::thread mThread;
};
-static int SndioPlayback_mixerProc(void *ptr);
+static int SndioPlayback_mixerProc(SndioPlayback *self);
static void SndioPlayback_Construct(SndioPlayback *self, ALCdevice *device);
static void SndioPlayback_Destruct(SndioPlayback *self);
@@ -86,9 +88,8 @@ static void SndioPlayback_Destruct(SndioPlayback *self)
}
-static int SndioPlayback_mixerProc(void *ptr)
+static int SndioPlayback_mixerProc(SndioPlayback *self)
{
- SndioPlayback *self = static_cast<SndioPlayback*>(ptr);
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
ALsizei frameSize;
size_t wrote;
@@ -249,23 +250,25 @@ static ALCboolean SndioPlayback_start(SndioPlayback *self)
return ALC_FALSE;
}
- self->mKillNow.store(AL_FALSE, std::memory_order_release);
- if(althrd_create(&self->thread, SndioPlayback_mixerProc, self) != althrd_success)
- {
- sio_stop(self->sndHandle);
- return ALC_FALSE;
+ try {
+ self->mKillNow.store(AL_FALSE, std::memory_order_release);
+ self->mThread = std::thread(SndioPlayback_mixerProc, self);
+ return ALC_TRUE;
}
-
- return ALC_TRUE;
+ catch(std::exception& e) {
+ ERR("Could not create playback thread: %s\n", e.what());
+ }
+ catch(...) {
+ }
+ sio_stop(self->sndHandle);
+ return ALC_FALSE;
}
static void SndioPlayback_stop(SndioPlayback *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;
- althrd_join(self->thread, &res);
+ self->mThread.join();
if(!sio_stop(self->sndHandle))
ERR("Error stopping device\n");
@@ -281,10 +284,10 @@ struct SndioCapture final : public ALCbackend {
ll_ringbuffer_t *ring{nullptr};
std::atomic<ALenum> mKillNow{AL_TRUE};
- althrd_t thread;
+ std::thread mThread;
};
-static int SndioCapture_recordProc(void *ptr);
+static int SndioCapture_recordProc(SndioCapture *self);
static void SndioCapture_Construct(SndioCapture *self, ALCdevice *device);
static void SndioCapture_Destruct(SndioCapture *self);
@@ -323,9 +326,8 @@ static void SndioCapture_Destruct(SndioCapture *self)
}
-static int SndioCapture_recordProc(void* ptr)
+static int SndioCapture_recordProc(SndioCapture *self)
{
- SndioCapture *self = static_cast<SndioCapture*>(ptr);
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
ALsizei frameSize;
@@ -490,23 +492,25 @@ static ALCboolean SndioCapture_start(SndioCapture *self)
return ALC_FALSE;
}
- self->mKillNow.store(AL_FALSE, std::memory_order_release);
- if(althrd_create(&self->thread, SndioCapture_recordProc, self) != althrd_success)
- {
- sio_stop(self->sndHandle);
- return ALC_FALSE;
+ try {
+ self->mKillNow.store(AL_FALSE, std::memory_order_release);
+ self->mThread = std::thread(SndioCapture_recordProc, self);
+ return ALC_TRUE;
}
-
- return ALC_TRUE;
+ catch(std::exception& e) {
+ ERR("Could not create record thread: %s\n", e.what());
+ }
+ catch(...) {
+ }
+ sio_stop(self->sndHandle);
+ return ALC_FALSE;
}
static void SndioCapture_stop(SndioCapture *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;
- althrd_join(self->thread, &res);
+ self->mThread.join();
if(!sio_stop(self->sndHandle))
ERR("Error stopping device\n");
diff --git a/Alc/backends/solaris.cpp b/Alc/backends/solaris.cpp
index 0ca7a4ec..941ca015 100644
--- a/Alc/backends/solaris.cpp
+++ b/Alc/backends/solaris.cpp
@@ -34,6 +34,8 @@
#include <errno.h>
#include <math.h>
+#include <thread>
+
#include "alMain.h"
#include "alu.h"
#include "alconfig.h"
@@ -50,10 +52,10 @@ struct ALCsolarisBackend final : public ALCbackend {
int data_size{0};
std::atomic<ALenum> mKillNow{AL_TRUE};
- althrd_t thread;
+ std::thread mThread;
};
-static int ALCsolarisBackend_mixerProc(void *ptr);
+static int ALCsolarisBackend_mixerProc(ALCsolarisBackend *self);
static void ALCsolarisBackend_Construct(ALCsolarisBackend *self, ALCdevice *device);
static void ALCsolarisBackend_Destruct(ALCsolarisBackend *self);
@@ -98,9 +100,8 @@ static void ALCsolarisBackend_Destruct(ALCsolarisBackend *self)
}
-static int ALCsolarisBackend_mixerProc(void *ptr)
+static int ALCsolarisBackend_mixerProc(ALCsolarisBackend *self)
{
- ALCsolarisBackend *self = static_cast<ALCsolarisBackend*>(ptr);
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
struct timeval timeout;
ALubyte *write_ptr;
@@ -268,20 +269,25 @@ static ALCboolean ALCsolarisBackend_reset(ALCsolarisBackend *self)
static ALCboolean ALCsolarisBackend_start(ALCsolarisBackend *self)
{
- self->mKillNow.store(AL_FALSE);
- if(althrd_create(&self->thread, ALCsolarisBackend_mixerProc, self) != althrd_success)
- return ALC_FALSE;
- return ALC_TRUE;
+ try {
+ self->mKillNow.store(AL_FALSE);
+ self->mThread = std::thread(ALCsolarisBackend_mixerProc, self);
+ return ALC_TRUE;
+ }
+ catch(std::exception& e) {
+ ERR("Could not create playback thread: %s\n", e.what());
+ }
+ catch(...) {
+ }
+ return ALC_FALSE;
}
static void ALCsolarisBackend_stop(ALCsolarisBackend *self)
{
- int res;
-
- if(self->mKillNow.exchange(AL_TRUE))
+ if(self->mKillNow.exchange(AL_TRUE) || !self->mThread.joinable())
return;
- althrd_join(self->thread, &res);
+ self->mThread.join();
if(ioctl(self->fd, AUDIO_DRAIN) < 0)
ERR("Error draining device: %s\n", strerror(errno));