diff options
author | Chris Robinson <[email protected]> | 2011-08-29 23:55:24 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-08-29 23:55:24 -0700 |
commit | f02d9e22d755e69baab00f1d7ddceced6bac8136 (patch) | |
tree | 5c424026e216af09cddeb07f96472a2ed299ff02 /OpenAL32/alSource.c | |
parent | cc67f4589256efceb17c58673159b3e687ec0436 (diff) |
Do a pointer exchange when replacing the source buffer queue
Diffstat (limited to 'OpenAL32/alSource.c')
-rw-r--r-- | OpenAL32/alSource.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 3e8d2b6a..9d4f048c 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -559,22 +559,14 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue) case AL_BUFFER: if(Source->state == AL_STOPPED || Source->state == AL_INITIAL) { + ALbufferlistitem *oldlist; ALbuffer *buffer = NULL; if(lValue == 0 || (buffer=LookupBuffer(device->BufferMap, lValue)) != NULL) { - // Remove all elements in the queue - while(Source->queue != NULL) - { - BufferListItem = Source->queue; - Source->queue = BufferListItem->next; - - if(BufferListItem->buffer) - DecrementRef(&BufferListItem->buffer->ref); - free(BufferListItem); - } Source->BuffersInQueue = 0; + Source->BuffersPlayed = 0; // Add the buffer to the queue (as long as it is NOT the NULL buffer) if(buffer != NULL) @@ -587,8 +579,10 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue) BufferListItem->buffer = buffer; BufferListItem->next = NULL; BufferListItem->prev = NULL; + // Increment reference counter for buffer + IncrementRef(&buffer->ref); - Source->queue = BufferListItem; + oldlist = ExchangePtr((void**)&Source->queue, BufferListItem); Source->BuffersInQueue = 1; Source->NumChannels = ChannelsFromFmt(buffer->FmtChannels); @@ -597,18 +591,25 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue) Source->Update = CalcSourceParams; else Source->Update = CalcNonAttnSourceParams; - - // Increment reference counter for buffer - IncrementRef(&buffer->ref); + Source->NeedsUpdate = AL_TRUE; } else { // Source is now in UNDETERMINED mode Source->lSourceType = AL_UNDETERMINED; + oldlist = ExchangePtr((void**)&Source->queue, NULL); } - Source->BuffersPlayed = 0; - Source->NeedsUpdate = AL_TRUE; + // Delete all previous elements in the queue + while(oldlist != NULL) + { + BufferListItem = oldlist; + oldlist = BufferListItem->next; + + if(BufferListItem->buffer) + DecrementRef(&BufferListItem->buffer->ref); + free(BufferListItem); + } } else alSetError(pContext, AL_INVALID_VALUE); |