aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32/alSource.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-05-11 03:11:35 -0700
committerChris Robinson <[email protected]>2014-05-11 03:11:35 -0700
commit9f8615c670e251cd8b2a513d11e156bcd0dea6d9 (patch)
treebd555e7d7bbb65de673dfa4a03889558532e5267 /OpenAL32/alSource.c
parent851a917b0347c3b47c9533f54c0a7ee1be3ffe45 (diff)
Avoid accessing the source's buffer queue head multiple times
Diffstat (limited to 'OpenAL32/alSource.c')
-rw-r--r--OpenAL32/alSource.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 8d7ab5e6..d707f226 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -2167,12 +2167,9 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALu
/* Source is now streaming */
source->SourceType = AL_STREAMING;
- if(!source->queue)
- source->queue = BufferListStart;
- else
+ if((BufferList=CompExchangePtr((XchgPtr*)&source->queue, NULL, BufferListStart)) != NULL)
{
- /* Append to the end of the queue */
- BufferList = source->queue;
+ /* Queue head is not NULL, append to the end of the queue */
while(BufferList->next != NULL)
BufferList = BufferList->next;
@@ -2191,6 +2188,7 @@ AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint
ALCcontext *context;
ALsource *source;
ALbufferlistitem *BufferList;
+ ALbufferlistitem *OldHead;
ALsizei i;
if(nb == 0)
@@ -2222,30 +2220,31 @@ AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint
}
/* Swap it, and cut the new head from the old. */
- BufferList = ExchangePtr((XchgPtr*)&source->queue, BufferList);
- if(source->queue)
+ OldHead = ExchangePtr((XchgPtr*)&source->queue, BufferList);
+ if(BufferList)
{
LockContext(context);
- source->queue->prev->next = NULL;
- source->queue->prev = NULL;
+ BufferList->prev->next = NULL;
+ BufferList->prev = NULL;
UnlockContext(context);
}
WriteUnlock(&source->queue_lock);
- for(i = 0;BufferList != NULL;i++)
+ while(OldHead != NULL)
{
- ALbufferlistitem *next = BufferList->next;
+ ALbufferlistitem *next = OldHead->next;
+ ALbuffer *buffer = OldHead->buffer;
- if(!BufferList->buffer)
- buffers[i] = 0;
+ if(!buffer)
+ *(buffers++) = 0;
else
{
- buffers[i] = BufferList->buffer->id;
- DecrementRef(&BufferList->buffer->ref);
+ *(buffers++) = buffer->id;
+ DecrementRef(&buffer->ref);
}
- free(BufferList);
- BufferList = next;
+ free(OldHead);
+ OldHead = next;
}
done: