aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-24 09:58:48 -0800
committerChris Robinson <[email protected]>2018-12-24 09:58:48 -0800
commitcd213fe6b731269caa484eb3cb9b830dac7f5c58 (patch)
tree587a40e4d34f592b6352a601d3547747d1ad3530 /Alc/backends
parent95631aa358a99b5f70a3edcebf2b76d1d4ae5af2 (diff)
Avoid using select()
Diffstat (limited to 'Alc/backends')
-rw-r--r--Alc/backends/oss.cpp64
-rw-r--r--Alc/backends/qsa.cpp36
-rw-r--r--Alc/backends/solaris.cpp37
3 files changed, 54 insertions, 83 deletions
diff --git a/Alc/backends/oss.cpp b/Alc/backends/oss.cpp
index 065f159a..4b1d468c 100644
--- a/Alc/backends/oss.cpp
+++ b/Alc/backends/oss.cpp
@@ -33,6 +33,7 @@
#include <memory.h>
#include <unistd.h>
#include <errno.h>
+#include <poll.h>
#include <math.h>
#include <atomic>
@@ -286,52 +287,44 @@ void ALCplaybackOSS_Destruct(ALCplaybackOSS *self)
int ALCplaybackOSS_mixerProc(ALCplaybackOSS *self)
{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- struct timeval timeout;
- ALubyte *write_ptr;
- ALint frame_size;
- ALint to_write;
- ssize_t wrote;
- fd_set wfds;
- int sret;
+ ALCdevice *device{STATIC_CAST(ALCbackend, self)->mDevice};
SetRTPriority();
althrd_setname(MIXER_THREAD_NAME);
- frame_size = device->frameSizeFromFmt();
+ const int frame_size{device->frameSizeFromFmt()};
ALCplaybackOSS_lock(self);
while(!self->mKillNow.load(std::memory_order_acquire) &&
device->Connected.load(std::memory_order_acquire))
{
- FD_ZERO(&wfds);
- FD_SET(self->fd, &wfds);
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
+ pollfd pollitem{};
+ pollitem.fd = self->fd;
+ pollitem.events = POLLOUT;
ALCplaybackOSS_unlock(self);
- sret = select(self->fd+1, nullptr, &wfds, nullptr, &timeout);
+ int pret{poll(&pollitem, 1, 1000)};
ALCplaybackOSS_lock(self);
- if(sret < 0)
+ if(pret < 0)
{
- if(errno == EINTR)
+ if(errno == EINTR || errno == EAGAIN)
continue;
- ERR("select failed: %s\n", strerror(errno));
+ ERR("poll failed: %s\n", strerror(errno));
aluHandleDisconnect(device, "Failed waiting for playback buffer: %s", strerror(errno));
break;
}
- else if(sret == 0)
+ else if(pret == 0)
{
- WARN("select timeout\n");
+ WARN("poll timeout\n");
continue;
}
- write_ptr = self->mMixData.data();
- to_write = self->mMixData.size();
+ ALubyte *write_ptr{self->mMixData.data()};
+ size_t to_write{self->mMixData.size()};
aluMixData(device, write_ptr, to_write/frame_size);
while(to_write > 0 && !self->mKillNow.load())
{
- wrote = write(self->fd, write_ptr, to_write);
+ ssize_t wrote{write(self->fd, write_ptr, to_write)};
if(wrote < 0)
{
if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
@@ -544,44 +537,37 @@ void ALCcaptureOSS_Destruct(ALCcaptureOSS *self)
int ALCcaptureOSS_recordProc(ALCcaptureOSS *self)
{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- struct timeval timeout;
- int frame_size;
- fd_set rfds;
- ssize_t amt;
- int sret;
+ ALCdevice *device{STATIC_CAST(ALCbackend, self)->mDevice};
SetRTPriority();
althrd_setname(RECORD_THREAD_NAME);
- frame_size = device->frameSizeFromFmt();
-
+ const int frame_size{device->frameSizeFromFmt()};
while(!self->mKillNow.load())
{
- FD_ZERO(&rfds);
- FD_SET(self->fd, &rfds);
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
+ pollfd pollitem{};
+ pollitem.fd = self->fd;
+ pollitem.events = POLLIN;
- sret = select(self->fd+1, &rfds, nullptr, nullptr, &timeout);
+ int sret{poll(&pollitem, 1, 1000)};
if(sret < 0)
{
- if(errno == EINTR)
+ if(errno == EINTR || errno == EAGAIN)
continue;
- ERR("select failed: %s\n", strerror(errno));
+ ERR("poll failed: %s\n", strerror(errno));
aluHandleDisconnect(device, "Failed to check capture samples: %s", strerror(errno));
break;
}
else if(sret == 0)
{
- WARN("select timeout\n");
+ WARN("poll timeout\n");
continue;
}
auto vec = ll_ringbuffer_get_write_vector(self->mRing.get());
if(vec.first.len > 0)
{
- amt = read(self->fd, vec.first.buf, vec.first.len*frame_size);
+ ssize_t amt{read(self->fd, vec.first.buf, vec.first.len*frame_size)};
if(amt < 0)
{
ERR("read failed: %s\n", strerror(errno));
diff --git a/Alc/backends/qsa.cpp b/Alc/backends/qsa.cpp
index f8b26878..f0d1876e 100644
--- a/Alc/backends/qsa.cpp
+++ b/Alc/backends/qsa.cpp
@@ -27,6 +27,7 @@
#include <sched.h>
#include <errno.h>
#include <memory.h>
+#include <poll.h>
#include <thread>
#include <memory>
@@ -36,7 +37,6 @@
#include "alu.h"
#include "threads.h"
-#include <sys/select.h>
#include <sys/asoundlib.h>
#include <sys/neutrino.h>
@@ -196,9 +196,7 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr)
qsa_data *data = self->ExtraData;
snd_pcm_channel_status_t status;
struct sched_param param;
- struct timeval timeout;
char* write_ptr;
- fd_set wfds;
ALint len;
int sret;
@@ -215,24 +213,25 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr)
PlaybackWrapper_lock(self);
while(!data->mKillNow.load(std::memory_order_acquire))
{
- FD_ZERO(&wfds);
- FD_SET(data->audio_fd, &wfds);
- timeout.tv_sec=2;
- timeout.tv_usec=0;
+ pollfd pollitem{};
+ pollitem.fd = data->audio_fd;
+ pollitem.events = POLLOUT;
/* Select also works like time slice to OS */
PlaybackWrapper_unlock(self);
- sret = select(data->audio_fd+1, NULL, &wfds, NULL, &timeout);
+ sret = poll(&pollitem, 1, 2000);
PlaybackWrapper_lock(self);
if(sret == -1)
{
- ERR("select error: %s\n", strerror(errno));
+ if(errno == EINTR || errno == EAGAIN)
+ continue;
+ ERR("poll error: %s\n", strerror(errno));
aluHandleDisconnect(device, "Failed waiting for playback buffer: %s", strerror(errno));
break;
}
if(sret == 0)
{
- ERR("select timeout\n");
+ ERR("poll timeout\n");
continue;
}
@@ -850,9 +849,7 @@ static ALCenum qsa_capture_samples(CaptureWrapper *self, ALCvoid *buffer, ALCuin
qsa_data *data = self->ExtraData.get();
char* read_ptr;
snd_pcm_channel_status_t status;
- fd_set rfds;
int selectret;
- struct timeval timeout;
int bytes_read;
ALint frame_size=device->frameSizeFromFmt();
ALint len=samples*frame_size;
@@ -862,14 +859,13 @@ static ALCenum qsa_capture_samples(CaptureWrapper *self, ALCvoid *buffer, ALCuin
while (len>0)
{
- FD_ZERO(&rfds);
- FD_SET(data->audio_fd, &rfds);
- timeout.tv_sec=2;
- timeout.tv_usec=0;
+ pollfd pollitem{};
+ pollitem.fd = data->audio_fd;
+ pollitem.events = POLLOUT;
/* Select also works like time slice to OS */
bytes_read=0;
- selectret=select(data->audio_fd+1, &rfds, NULL, NULL, &timeout);
+ selectret = poll(&pollitem, 1, 2000);
switch (selectret)
{
case -1:
@@ -878,11 +874,7 @@ static ALCenum qsa_capture_samples(CaptureWrapper *self, ALCvoid *buffer, ALCuin
case 0:
break;
default:
- if (FD_ISSET(data->audio_fd, &rfds))
- {
- bytes_read=snd_pcm_plugin_read(data->pcmHandle, read_ptr, len);
- break;
- }
+ bytes_read=snd_pcm_plugin_read(data->pcmHandle, read_ptr, len);
break;
}
diff --git a/Alc/backends/solaris.cpp b/Alc/backends/solaris.cpp
index 8871fb93..79341ad1 100644
--- a/Alc/backends/solaris.cpp
+++ b/Alc/backends/solaris.cpp
@@ -32,6 +32,7 @@
#include <memory.h>
#include <unistd.h>
#include <errno.h>
+#include <poll.h>
#include <math.h>
#include <thread>
@@ -102,52 +103,44 @@ static void ALCsolarisBackend_Destruct(ALCsolarisBackend *self)
static int ALCsolarisBackend_mixerProc(ALCsolarisBackend *self)
{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- struct timeval timeout;
- ALubyte *write_ptr;
- ALint frame_size;
- ALint to_write;
- ssize_t wrote;
- fd_set wfds;
- int sret;
+ ALCdevice *device{STATIC_CAST(ALCbackend, self)->mDevice};
SetRTPriority();
althrd_setname(MIXER_THREAD_NAME);
- frame_size = device->frameSizeFromFmt();
+ const int frame_size{device->frameSizeFromFmt()};
ALCsolarisBackend_lock(self);
while(!self->mKillNow.load(std::memory_order_acquire) &&
device->Connected.load(std::memory_order_acquire))
{
- FD_ZERO(&wfds);
- FD_SET(self->fd, &wfds);
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
+ pollfd pollitem{};
+ pollitem.fd = self->fd;
+ pollitem.events = POLLOUT;
ALCsolarisBackend_unlock(self);
- sret = select(self->fd+1, nullptr, &wfds, nullptr, &timeout);
+ int pret{poll(&pollitem, 1, 1000)};
ALCsolarisBackend_lock(self);
- if(sret < 0)
+ if(pret < 0)
{
- if(errno == EINTR)
+ if(errno == EINTR || errno == EAGAIN)
continue;
- ERR("select failed: %s\n", strerror(errno));
+ ERR("poll failed: %s\n", strerror(errno));
aluHandleDisconnect(device, "Failed to wait for playback buffer: %s", strerror(errno));
break;
}
- else if(sret == 0)
+ else if(pret == 0)
{
- WARN("select timeout\n");
+ WARN("poll timeout\n");
continue;
}
- write_ptr = self->mix_data;
- to_write = self->data_size;
+ ALubyte *write_ptr{self->mix_data};
+ int to_write{self->data_size};
aluMixData(device, write_ptr, to_write/frame_size);
while(to_write > 0 && !self->mKillNow.load())
{
- wrote = write(self->fd, write_ptr, to_write);
+ ssize_t wrote{write(self->fd, write_ptr, to_write)};
if(wrote < 0)
{
if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)