From 849f85549d47a4e1aecdfbdd3300c866fb288fca Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 24 Aug 2016 02:17:55 -0700 Subject: Consolidate duplicate code --- Alc/ALu.c | 62 +++++++++++++++++++++++--------------------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) (limited to 'Alc/ALu.c') diff --git a/Alc/ALu.c b/Alc/ALu.c index 54905ebd..80a031fc 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -1296,54 +1296,38 @@ static void CalcSourceParams(ALvoice *voice, ALCcontext *context, ALboolean forc struct ALsourceProps *props; props = ATOMIC_EXCHANGE(struct ALsourceProps*, &source->Update, NULL, almemory_order_acq_rel); - if(!props) - { - if(!force) - return; - BufferListItem = ATOMIC_LOAD(&source->queue, almemory_order_relaxed); - while(BufferListItem != NULL) - { - const ALbuffer *buffer; - if((buffer=BufferListItem->buffer) != NULL) - { - if(buffer->FmtChannels == FmtMono) - CalcAttnSourceParams(voice, &voice->Props, buffer, context); - else - CalcNonAttnSourceParams(voice, &voice->Props, buffer, context); - break; - } - BufferListItem = BufferListItem->next; - } - } - else + if(!props && !force) return; + + if(props) { - BufferListItem = ATOMIC_LOAD(&source->queue, almemory_order_relaxed); - while(BufferListItem != NULL) - { - const ALbuffer *buffer; - if((buffer=BufferListItem->buffer) != NULL) - { - if(buffer->FmtChannels == FmtMono) - CalcAttnSourceParams(voice, props, buffer, context); - else - CalcNonAttnSourceParams(voice, props, buffer, context); - break; - } - BufferListItem = BufferListItem->next; - } voice->Props = *props; - /* WARNING: A livelock is theoretically possible if another thread keeps - * changing the freelist head without giving this a chance to actually swap - * in the old container (practically impossible with this little code, - * but...). - */ + /* WARNING: A livelock is theoretically possible if another thread + * keeps changing the freelist head without giving this a chance to + * actually swap in the old container (practically impossible with this + * little code, but...). + */ first = ATOMIC_LOAD(&source->FreeList); do { ATOMIC_STORE(&props->next, first, almemory_order_relaxed); } while(ATOMIC_COMPARE_EXCHANGE_WEAK(struct ALsourceProps*, &source->FreeList, &first, props) == 0); } + + BufferListItem = ATOMIC_LOAD(&source->queue, almemory_order_relaxed); + while(BufferListItem != NULL) + { + const ALbuffer *buffer; + if((buffer=BufferListItem->buffer) != NULL) + { + if(buffer->FmtChannels == FmtMono) + CalcAttnSourceParams(voice, &voice->Props, buffer, context); + else + CalcNonAttnSourceParams(voice, &voice->Props, buffer, context); + break; + } + BufferListItem = BufferListItem->next; + } } -- cgit v1.2.3