aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-26 14:31:54 -0800
committerChris Robinson <[email protected]>2018-11-26 14:31:54 -0800
commita6923790fac739f0b98db6c06bc93543b9707556 (patch)
treee30677dd529ba0a2fecb6cbd6232f862acdc27dd
parent5b2b96b24598636e35f1fe7ecf868b09571065d6 (diff)
Avoid using ATOMIC_INIT
-rw-r--r--Alc/alc.cpp4
-rw-r--r--Alc/backends/jack.cpp15
-rw-r--r--Alc/backends/null.cpp4
-rw-r--r--Alc/backends/opensl.cpp44
-rw-r--r--Alc/backends/qsa.cpp2
-rw-r--r--Alc/backends/sndio.cpp22
-rw-r--r--Alc/backends/solaris.cpp12
-rw-r--r--Alc/backends/wave.cpp11
-rw-r--r--Alc/ringbuffer.cpp23
-rw-r--r--OpenAL32/alSource.cpp6
-rw-r--r--common/atomic.h4
11 files changed, 49 insertions, 98 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index a3c6b5bd..ea72757c 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -2534,7 +2534,7 @@ static ALvoid InitContext(ALCcontext *Context)
sizeof(struct ALeffectslotArray)));
auxslots->count = 0;
}
- ATOMIC_INIT(&Context->ActiveAuxSlots, auxslots);
+ Context->ActiveAuxSlots.store(auxslots, std::memory_order_relaxed);
//Set globals
Context->mDistanceModel = DistanceModel::Default;
@@ -2850,7 +2850,7 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends)
/* Finish setting the voices' property set pointers and references. */
for(;v < num_voices;v++)
{
- ATOMIC_INIT(&voice->Update, static_cast<ALvoiceProps*>(nullptr));
+ voice->Update.store(nullptr, std::memory_order_relaxed);
voice->Props = props;
voices[v] = voice;
diff --git a/Alc/backends/jack.cpp b/Alc/backends/jack.cpp
index cd02388d..d0687939 100644
--- a/Alc/backends/jack.cpp
+++ b/Alc/backends/jack.cpp
@@ -145,13 +145,13 @@ static ALCboolean jack_load(void)
struct ALCjackPlayback final : public ALCbackend {
- jack_client_t *Client;
- jack_port_t *Port[MAX_OUTPUT_CHANNELS];
+ jack_client_t *Client{nullptr};
+ jack_port_t *Port[MAX_OUTPUT_CHANNELS]{};
- ll_ringbuffer_t *Ring;
+ ll_ringbuffer_t *Ring{nullptr};
alsem_t Sem;
- ATOMIC(ALenum) killNow;
+ ATOMIC(ALenum) killNow{AL_TRUE};
althrd_t thread;
};
@@ -183,13 +183,6 @@ static void ALCjackPlayback_Construct(ALCjackPlayback *self, ALCdevice *device)
SET_VTABLE2(ALCjackPlayback, ALCbackend, self);
alsem_init(&self->Sem, 0);
-
- self->Client = NULL;
- for(ALsizei i{0};i < MAX_OUTPUT_CHANNELS;i++)
- self->Port[i] = NULL;
- self->Ring = NULL;
-
- ATOMIC_INIT(&self->killNow, AL_TRUE);
}
static void ALCjackPlayback_Destruct(ALCjackPlayback *self)
diff --git a/Alc/backends/null.cpp b/Alc/backends/null.cpp
index 47ebd0ae..7c7f5e5e 100644
--- a/Alc/backends/null.cpp
+++ b/Alc/backends/null.cpp
@@ -45,7 +45,7 @@ constexpr ALCchar nullDevice[] = "No Output";
struct ALCnullBackend final : public ALCbackend {
- ATOMIC(int) killNow;
+ ATOMIC(int) killNow{AL_TRUE};
std::thread thread;
};
@@ -72,8 +72,6 @@ void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device)
new (self) ALCnullBackend{};
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCnullBackend, ALCbackend, self);
-
- ATOMIC_INIT(&self->killNow, AL_TRUE);
}
void ALCnullBackend_Destruct(ALCnullBackend *self)
diff --git a/Alc/backends/opensl.cpp b/Alc/backends/opensl.cpp
index f7ad1595..5b80ea65 100644
--- a/Alc/backends/opensl.cpp
+++ b/Alc/backends/opensl.cpp
@@ -134,21 +134,21 @@ static const char *res_str(SLresult result)
struct ALCopenslPlayback final : public ALCbackend {
/* engine interfaces */
- SLObjectItf mEngineObj;
- SLEngineItf mEngine;
+ SLObjectItf mEngineObj{nullptr};
+ SLEngineItf mEngine{nullptr};
/* output mix interfaces */
- SLObjectItf mOutputMix;
+ SLObjectItf mOutputMix{nullptr};
/* buffer queue player interfaces */
- SLObjectItf mBufferQueueObj;
+ SLObjectItf mBufferQueueObj{nullptr};
- ll_ringbuffer_t *mRing;
+ ll_ringbuffer_t *mRing{nullptr};
alsem_t mSem;
- ALsizei mFrameSize;
+ ALsizei mFrameSize{0};
- ATOMIC(ALenum) mKillNow;
+ ATOMIC(ALenum) mKillNow{AL_TRUE};
althrd_t mThread;
};
@@ -177,17 +177,7 @@ static void ALCopenslPlayback_Construct(ALCopenslPlayback *self, ALCdevice *devi
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCopenslPlayback, ALCbackend, self);
- self->mEngineObj = NULL;
- self->mEngine = NULL;
- self->mOutputMix = NULL;
- self->mBufferQueueObj = NULL;
-
- self->mRing = NULL;
alsem_init(&self->mSem, 0);
-
- self->mFrameSize = 0;
-
- ATOMIC_INIT(&self->mKillNow, AL_FALSE);
}
static void ALCopenslPlayback_Destruct(ALCopenslPlayback* self)
@@ -664,16 +654,16 @@ static ClockLatency ALCopenslPlayback_getClockLatency(ALCopenslPlayback *self)
struct ALCopenslCapture final : public ALCbackend {
/* engine interfaces */
- SLObjectItf mEngineObj;
+ SLObjectItf mEngineObj{nullptr};
SLEngineItf mEngine;
/* recording interfaces */
- SLObjectItf mRecordObj;
+ SLObjectItf mRecordObj{nullptr};
- ll_ringbuffer_t *mRing;
- ALCuint mSplOffset;
+ ll_ringbuffer_t *mRing{nullptr};
+ ALCuint mSplOffset{0u};
- ALsizei mFrameSize;
+ ALsizei mFrameSize{0};
};
static void ALCopenslCapture_process(SLAndroidSimpleBufferQueueItf bq, void *context);
@@ -698,16 +688,6 @@ static void ALCopenslCapture_Construct(ALCopenslCapture *self, ALCdevice *device
new (self) ALCopenslCapture{};
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCopenslCapture, ALCbackend, self);
-
- self->mEngineObj = NULL;
- self->mEngine = NULL;
-
- self->mRecordObj = NULL;
-
- self->mRing = NULL;
- self->mSplOffset = 0;
-
- self->mFrameSize = 0;
}
static void ALCopenslCapture_Destruct(ALCopenslCapture *self)
diff --git a/Alc/backends/qsa.cpp b/Alc/backends/qsa.cpp
index 09082357..a6d1e0ea 100644
--- a/Alc/backends/qsa.cpp
+++ b/Alc/backends/qsa.cpp
@@ -289,7 +289,7 @@ static ALCenum qsa_open_playback(PlaybackWrapper *self, const ALCchar* deviceNam
data = (qsa_data*)calloc(1, sizeof(qsa_data));
if(data == NULL)
return ALC_OUT_OF_MEMORY;
- ATOMIC_INIT(&data->killNow, AL_TRUE);
+ data->killNow.store(AL_TRUE, std::memory_order_relaxed);
if(!deviceName)
deviceName = qsaDevice;
diff --git a/Alc/backends/sndio.cpp b/Alc/backends/sndio.cpp
index 2a20fb61..de5f74e4 100644
--- a/Alc/backends/sndio.cpp
+++ b/Alc/backends/sndio.cpp
@@ -38,12 +38,12 @@ static const ALCchar sndio_device[] = "SndIO Default";
struct SndioPlayback final : public ALCbackend {
- struct sio_hdl *sndHandle;
+ struct sio_hdl *sndHandle{nullptr};
- ALvoid *mix_data;
- ALsizei data_size;
+ ALvoid *mix_data{nullptr};
+ ALsizei data_size{0};
- ATOMIC(int) killNow;
+ ATOMIC(int) killNow{AL_TRUE};
althrd_t thread;
};
@@ -70,10 +70,6 @@ static void SndioPlayback_Construct(SndioPlayback *self, ALCdevice *device)
new (self) SndioPlayback{};
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(SndioPlayback, ALCbackend, self);
-
- self->sndHandle = nullptr;
- self->mix_data = nullptr;
- ATOMIC_INIT(&self->killNow, AL_TRUE);
}
static void SndioPlayback_Destruct(SndioPlayback *self)
@@ -280,11 +276,11 @@ static void SndioPlayback_stop(SndioPlayback *self)
struct SndioCapture final : public ALCbackend {
- struct sio_hdl *sndHandle;
+ struct sio_hdl *sndHandle{nullptr};
- ll_ringbuffer_t *ring;
+ ll_ringbuffer_t *ring{nullptr};
- ATOMIC(int) killNow;
+ ATOMIC(int) killNow{AL_TRUE};
althrd_t thread;
};
@@ -311,10 +307,6 @@ static void SndioCapture_Construct(SndioCapture *self, ALCdevice *device)
new (self) SndioCapture{};
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(SndioCapture, ALCbackend, self);
-
- self->sndHandle = nullptr;
- self->ring = nullptr;
- ATOMIC_INIT(&self->killNow, AL_TRUE);
}
static void SndioCapture_Destruct(SndioCapture *self)
diff --git a/Alc/backends/solaris.cpp b/Alc/backends/solaris.cpp
index c757e5e1..93de4384 100644
--- a/Alc/backends/solaris.cpp
+++ b/Alc/backends/solaris.cpp
@@ -44,12 +44,12 @@
struct ALCsolarisBackend final : public ALCbackend {
- int fd;
+ int fd{-1};
- ALubyte *mix_data;
- int data_size;
+ ALubyte *mix_data{nullptr};
+ int data_size{0};
- ATOMIC(ALenum) killNow;
+ ATOMIC(ALenum) killNow{AL_TRUE};
althrd_t thread;
};
@@ -81,10 +81,6 @@ static void ALCsolarisBackend_Construct(ALCsolarisBackend *self, ALCdevice *devi
new (self) ALCsolarisBackend{};
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCsolarisBackend, ALCbackend, self);
-
- self->fd = -1;
- self->mix_data = nullptr;
- ATOMIC_INIT(&self->killNow, AL_FALSE);
}
static void ALCsolarisBackend_Destruct(ALCsolarisBackend *self)
diff --git a/Alc/backends/wave.cpp b/Alc/backends/wave.cpp
index d9219336..bb37d979 100644
--- a/Alc/backends/wave.cpp
+++ b/Alc/backends/wave.cpp
@@ -79,12 +79,12 @@ void fwrite32le(ALuint val, FILE *f)
struct ALCwaveBackend final : public ALCbackend {
- FILE *mFile;
- long mDataStart;
+ FILE *mFile{nullptr};
+ long mDataStart{-1};
al::vector<ALbyte> mBuffer;
- ATOMIC(ALenum) killNow;
+ ATOMIC(ALenum) killNow{AL_TRUE};
std::thread thread;
};
@@ -111,11 +111,6 @@ void ALCwaveBackend_Construct(ALCwaveBackend *self, ALCdevice *device)
new (self) ALCwaveBackend{};
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCwaveBackend, ALCbackend, self);
-
- self->mFile = nullptr;
- self->mDataStart = -1;
-
- ATOMIC_INIT(&self->killNow, AL_TRUE);
}
void ALCwaveBackend_Destruct(ALCwaveBackend *self)
diff --git a/Alc/ringbuffer.cpp b/Alc/ringbuffer.cpp
index e5f0f554..db44f8ae 100644
--- a/Alc/ringbuffer.cpp
+++ b/Alc/ringbuffer.cpp
@@ -36,13 +36,15 @@
* size or count is in 'elements', not bytes. Additionally, it only supports
* single-consumer/single-provider operation. */
struct ll_ringbuffer {
- std::atomic<size_t> write_ptr;
- std::atomic<size_t> read_ptr;
- size_t size;
- size_t size_mask;
- size_t elem_size;
+ std::atomic<size_t> write_ptr{0u};
+ std::atomic<size_t> read_ptr{0u};
+ size_t size{0u};
+ size_t size_mask{0u};
+ size_t elem_size{0u};
alignas(16) char buf[];
+
+ DEF_PLACE_NEWDEL()
};
ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz, int limit_writes)
@@ -65,11 +67,8 @@ ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz, int limit_write
power_of_two++;
if(power_of_two < sz) return NULL;
- rb = static_cast<ll_ringbuffer_t*>(al_malloc(16, sizeof(*rb) + power_of_two*elem_sz));
- if(!rb) return NULL;
+ rb = new (al_malloc(16, sizeof(*rb) + power_of_two*elem_sz)) ll_ringbuffer{};
- ATOMIC_INIT(&rb->write_ptr, static_cast<size_t>(0));
- ATOMIC_INIT(&rb->read_ptr, static_cast<size_t>(0));
rb->size = limit_writes ? sz : power_of_two;
rb->size_mask = power_of_two - 1;
rb->elem_size = elem_sz;
@@ -78,13 +77,13 @@ ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz, int limit_write
void ll_ringbuffer_free(ll_ringbuffer_t *rb)
{
- al_free(rb);
+ delete rb;
}
void ll_ringbuffer_reset(ll_ringbuffer_t *rb)
{
- rb->write_ptr.store(0, std::memory_order_release);
- rb->read_ptr.store(0, std::memory_order_release);
+ rb->write_ptr.store(0, std::memory_order_relaxed);
+ rb->read_ptr.store(0, std::memory_order_relaxed);
memset(rb->buf, 0, (rb->size_mask+1)*rb->elem_size);
}
diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp
index 12a8a04a..e58d6314 100644
--- a/OpenAL32/alSource.cpp
+++ b/OpenAL32/alSource.cpp
@@ -1276,7 +1276,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co
/* Add the selected buffer to a one-item queue */
auto newlist = static_cast<ALbufferlistitem*>(al_calloc(DEF_ALIGN,
FAM_SIZE(ALbufferlistitem, buffers, 1)));
- ATOMIC_INIT(&newlist->next, static_cast<ALbufferlistitem*>(nullptr));
+ newlist->next.store(nullptr, std::memory_order_relaxed);
newlist->max_samples = buffer->SampleLen;
newlist->num_buffers = 1;
newlist->buffers[0] = buffer;
@@ -3034,7 +3034,7 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALu
BufferList->next.store(item, std::memory_order_relaxed);
BufferList = item;
}
- ATOMIC_INIT(&BufferList->next, static_cast<ALbufferlistitem*>(nullptr));
+ BufferList->next.store(nullptr, std::memory_order_relaxed);
BufferList->max_samples = buffer ? buffer->SampleLen : 0;
BufferList->num_buffers = 1;
BufferList->buffers[0] = buffer;
@@ -3129,7 +3129,7 @@ AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb, co
auto BufferListStart = static_cast<ALbufferlistitem*>(al_calloc(DEF_ALIGN,
FAM_SIZE(ALbufferlistitem, buffers, nb)));
BufferList = BufferListStart;
- ATOMIC_INIT(&BufferList->next, static_cast<ALbufferlistitem*>(nullptr));
+ BufferList->next.store(nullptr, std::memory_order_relaxed);
BufferList->max_samples = 0;
BufferList->num_buffers = 0;
diff --git a/common/atomic.h b/common/atomic.h
index 87560e3d..eaae8fb8 100644
--- a/common/atomic.h
+++ b/common/atomic.h
@@ -14,8 +14,6 @@
#define ATOMIC(T) std::atomic<T>
-#define ATOMIC_INIT std::atomic_init
-
#define ATOMIC_LOAD std::atomic_load_explicit
#define ATOMIC_STORE std::atomic_store_explicit
@@ -33,7 +31,7 @@
using RefCount = std::atomic<unsigned int>;
inline void InitRef(RefCount *ptr, unsigned int value)
-{ ATOMIC_INIT(ptr, value); }
+{ ptr->store(value, std::memory_order_relaxed); }
inline unsigned int ReadRef(RefCount *ptr)
{ return ptr->load(std::memory_order_acquire); }
inline unsigned int IncrementRef(RefCount *ptr)