aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-05-19 20:50:55 -0700
committerChris Robinson <[email protected]>2016-05-19 20:50:55 -0700
commit7bf64eaee0788b7eb64c7410384a9ee66f75c4ce (patch)
treeb0b410caa1aa380fb329ff982f881a958f7eaec0
parentd80f00173f0ef623f69a9cc307457b198186ded8 (diff)
Make the source position calues atomic
-rw-r--r--Alc/ALu.c4
-rw-r--r--Alc/mixer.c14
-rw-r--r--OpenAL32/Include/alSource.h4
-rw-r--r--OpenAL32/alSource.c39
4 files changed, 31 insertions, 30 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 44361979..ec0dd011 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -1619,8 +1619,8 @@ ALvoid aluHandleDisconnect(ALCdevice *device)
{
source->state = AL_STOPPED;
ATOMIC_STORE(&source->current_buffer, NULL);
- source->position = 0;
- source->position_fraction = 0;
+ ATOMIC_STORE(&source->position, 0);
+ ATOMIC_STORE(&source->position_fraction, 0);
}
voice++;
diff --git a/Alc/mixer.c b/Alc/mixer.c
index 38ec295c..1ee422be 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -384,10 +384,10 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
ALuint chan, j;
/* Get source info */
- State = Source->state;
+ State = AL_PLAYING; /* Only called while playing. */
BufferListItem = ATOMIC_LOAD(&Source->current_buffer);
- DataPosInt = Source->position;
- DataPosFrac = Source->position_fraction;
+ DataPosInt = ATOMIC_LOAD(&Source->position, almemory_order_relaxed);
+ DataPosFrac = ATOMIC_LOAD(&Source->position_fraction, almemory_order_relaxed);
NumChannels = Source->NumChannels;
SampleSize = Source->SampleSize;
Looping = voice->Looping;
@@ -752,8 +752,8 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
voice->Moving = AL_TRUE;
/* Update source info */
- Source->state = State;
- ATOMIC_STORE(&Source->current_buffer, BufferListItem);
- Source->position = DataPosInt;
- Source->position_fraction = DataPosFrac;
+ Source->state = State;
+ ATOMIC_STORE(&Source->current_buffer, BufferListItem, almemory_order_relaxed);
+ ATOMIC_STORE(&Source->position, DataPosInt, almemory_order_relaxed);
+ ATOMIC_STORE(&Source->position_fraction, DataPosFrac);
}
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h
index fbd63ce2..bb1e6434 100644
--- a/OpenAL32/Include/alSource.h
+++ b/OpenAL32/Include/alSource.h
@@ -172,8 +172,8 @@ typedef struct ALsource {
* the whole queue, and the fractional (fixed-point) offset to the next
* sample.
*/
- ALuint position;
- ALuint position_fraction;
+ ATOMIC(ALuint) position;
+ ATOMIC(ALuint) position_fraction;
/** Source Buffer Queue info. */
ATOMIC(ALbufferlistitem*) queue;
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 780e9061..a0e40c1d 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -2904,8 +2904,8 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
if(Source->state != AL_PAUSED)
{
Source->state = AL_PLAYING;
- Source->position = 0;
- Source->position_fraction = 0;
+ ATOMIC_STORE(&Source->position, 0, almemory_order_relaxed);
+ ATOMIC_STORE(&Source->position_fraction, 0, almemory_order_relaxed);
ATOMIC_STORE(&Source->current_buffer, BufferList);
discontinuity = AL_TRUE;
}
@@ -2991,8 +2991,8 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
if(Source->state != AL_INITIAL)
{
Source->state = AL_INITIAL;
- Source->position = 0;
- Source->position_fraction = 0;
+ ATOMIC_STORE(&Source->position, 0, almemory_order_relaxed);
+ ATOMIC_STORE(&Source->position_fraction, 0, almemory_order_relaxed);
ATOMIC_STORE(&Source->current_buffer, ATOMIC_LOAD(&Source->queue));
}
Source->OffsetType = AL_NONE;
@@ -3022,10 +3022,11 @@ ALint64 GetSourceSampleOffset(ALsource *Source)
/* NOTE: This is the offset into the *current* buffer, so add the length of
* any played buffers */
- readPos = (ALuint64)Source->position << 32;
- readPos |= (ALuint64)Source->position_fraction << (32-FRACTIONBITS);
- BufferList = ATOMIC_LOAD(&Source->queue);
- Current = ATOMIC_LOAD(&Source->current_buffer);
+ readPos = (ALuint64)ATOMIC_LOAD(&Source->position) << 32;
+ readPos |= (ALuint64)ATOMIC_LOAD(&Source->position_fraction, almemory_order_relaxed) <<
+ (32-FRACTIONBITS);
+ BufferList = ATOMIC_LOAD(&Source->queue, almemory_order_relaxed);
+ Current = ATOMIC_LOAD(&Source->current_buffer, almemory_order_relaxed);
while(BufferList && BufferList != Current)
{
if(BufferList->buffer)
@@ -3058,10 +3059,10 @@ static ALdouble GetSourceSecOffset(ALsource *Source)
/* NOTE: This is the offset into the *current* buffer, so add the length of
* any played buffers */
- readPos = (ALuint64)Source->position << FRACTIONBITS;
- readPos |= (ALuint64)Source->position_fraction;
- BufferList = ATOMIC_LOAD(&Source->queue);
- Current = ATOMIC_LOAD(&Source->current_buffer);
+ readPos = (ALuint64)ATOMIC_LOAD(&Source->position) << FRACTIONBITS;
+ readPos |= (ALuint64)ATOMIC_LOAD(&Source->position_fraction, almemory_order_relaxed);
+ BufferList = ATOMIC_LOAD(&Source->queue, almemory_order_relaxed);
+ Current = ATOMIC_LOAD(&Source->current_buffer, almemory_order_relaxed);
while(BufferList && BufferList != Current)
{
const ALbuffer *buffer = BufferList->buffer;
@@ -3110,10 +3111,10 @@ static ALdouble GetSourceOffset(ALsource *Source, ALenum name)
/* NOTE: This is the offset into the *current* buffer, so add the length of
* any played buffers */
totalBufferLen = 0;
- readPos = Source->position;
- readPosFrac = Source->position_fraction;
- BufferList = ATOMIC_LOAD(&Source->queue);
- Current = ATOMIC_LOAD(&Source->current_buffer);
+ readPos = ATOMIC_LOAD(&Source->position);
+ readPosFrac = ATOMIC_LOAD(&Source->position_fraction, almemory_order_relaxed);
+ BufferList = ATOMIC_LOAD(&Source->queue, almemory_order_relaxed);
+ Current = ATOMIC_LOAD(&Source->current_buffer, almemory_order_relaxed);
while(BufferList != NULL)
{
const ALbuffer *buffer;
@@ -3205,10 +3206,10 @@ ALboolean ApplyOffset(ALsource *Source)
if(bufferLen > offset-totalBufferLen)
{
/* Offset is in this buffer */
- ATOMIC_STORE(&Source->current_buffer, BufferList);
+ ATOMIC_STORE(&Source->current_buffer, BufferList, almemory_order_relaxed);
- Source->position = offset - totalBufferLen;
- Source->position_fraction = frac;
+ ATOMIC_STORE(&Source->position, offset - totalBufferLen, almemory_order_relaxed);
+ ATOMIC_STORE(&Source->position_fraction, frac);
return AL_TRUE;
}