Avoid duplicating code using a macro
This commit is contained in:
@@ -239,7 +239,6 @@ static ALboolean CalcListenerParams(ALCcontext *Context)
|
||||
{
|
||||
ALlistener *Listener = Context->Listener;
|
||||
ALfloat N[3], V[3], U[3], P[3];
|
||||
struct ALlistenerProps *first;
|
||||
struct ALlistenerProps *props;
|
||||
aluVector vel;
|
||||
|
||||
@@ -288,24 +287,12 @@ static ALboolean CalcListenerParams(ALCcontext *Context)
|
||||
Listener->Params.SourceDistanceModel = ATOMIC_LOAD(&props->SourceDistanceModel, almemory_order_relaxed);
|
||||
Listener->Params.DistanceModel = ATOMIC_LOAD(&props->DistanceModel, almemory_order_relaxed);
|
||||
|
||||
/* 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(&Listener->FreeList, almemory_order_acquire);
|
||||
do {
|
||||
ATOMIC_STORE(&props->next, first, almemory_order_relaxed);
|
||||
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(struct ALlistenerProps*,
|
||||
&Listener->FreeList, &first, props, almemory_order_acq_rel,
|
||||
almemory_order_acquire) == 0);
|
||||
|
||||
ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &Listener->FreeList, props);
|
||||
return AL_TRUE;
|
||||
}
|
||||
|
||||
static ALboolean CalcEffectSlotParams(ALeffectslot *slot, ALCdevice *device)
|
||||
{
|
||||
struct ALeffectslotProps *first;
|
||||
struct ALeffectslotProps *props;
|
||||
ALeffectState *state;
|
||||
|
||||
@@ -337,18 +324,7 @@ static ALboolean CalcEffectSlotParams(ALeffectslot *slot, ALCdevice *device)
|
||||
|
||||
V(state,update)(device, slot, &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...).
|
||||
*/
|
||||
first = ATOMIC_LOAD(&slot->FreeList, almemory_order_acquire);
|
||||
do {
|
||||
ATOMIC_STORE(&props->next, first, almemory_order_relaxed);
|
||||
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(struct ALeffectslotProps*,
|
||||
&slot->FreeList, &first, props, almemory_order_acq_rel,
|
||||
almemory_order_acquire) == 0);
|
||||
|
||||
ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &slot->FreeList, props);
|
||||
return AL_TRUE;
|
||||
}
|
||||
|
||||
@@ -1301,7 +1277,6 @@ static void CalcSourceParams(ALvoice *voice, ALCcontext *context, ALboolean forc
|
||||
{
|
||||
ALsource *source = voice->Source;
|
||||
const ALbufferlistitem *BufferListItem;
|
||||
struct ALsourceProps *first;
|
||||
struct ALsourceProps *props;
|
||||
|
||||
props = ATOMIC_EXCHANGE(struct ALsourceProps*, &source->Update, NULL, almemory_order_acq_rel);
|
||||
@@ -1311,17 +1286,7 @@ static void CalcSourceParams(ALvoice *voice, ALCcontext *context, ALboolean forc
|
||||
{
|
||||
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...).
|
||||
*/
|
||||
first = ATOMIC_LOAD(&source->FreeList, almemory_order_acquire);
|
||||
do {
|
||||
ATOMIC_STORE(&props->next, first, almemory_order_relaxed);
|
||||
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(struct ALsourceProps*,
|
||||
&source->FreeList, &first, props, almemory_order_acq_rel,
|
||||
almemory_order_acquire) == 0);
|
||||
ATOMIC_REPLACE_HEAD(struct ALsourceProps*, &source->FreeList, props);
|
||||
}
|
||||
|
||||
BufferListItem = ATOMIC_LOAD(&source->queue, almemory_order_relaxed);
|
||||
|
||||
@@ -671,11 +671,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot)
|
||||
/* If there was an unused update container, put it back in the
|
||||
* freelist.
|
||||
*/
|
||||
struct ALeffectslotProps *first = ATOMIC_LOAD_SEQ(&slot->FreeList);
|
||||
do {
|
||||
ATOMIC_STORE(&props->next, first, almemory_order_relaxed);
|
||||
} while(ATOMIC_COMPARE_EXCHANGE_WEAK_SEQ(struct ALeffectslotProps*,
|
||||
&slot->FreeList, &first, props) == 0);
|
||||
ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &slot->FreeList, props);
|
||||
}
|
||||
|
||||
if(oldstate)
|
||||
|
||||
@@ -506,10 +506,6 @@ void UpdateListenerProps(ALCcontext *context)
|
||||
/* If there was an unused update container, put it back in the
|
||||
* freelist.
|
||||
*/
|
||||
struct ALlistenerProps *first = ATOMIC_LOAD_SEQ(&listener->FreeList);
|
||||
do {
|
||||
ATOMIC_STORE(&props->next, first, almemory_order_relaxed);
|
||||
} while(ATOMIC_COMPARE_EXCHANGE_WEAK_SEQ(struct ALlistenerProps*,
|
||||
&listener->FreeList, &first, props) == 0);
|
||||
ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &listener->FreeList, props);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-6
@@ -2913,12 +2913,7 @@ static void UpdateSourceProps(ALsource *source, ALuint num_sends)
|
||||
/* If there was an unused update container, put it back in the
|
||||
* freelist.
|
||||
*/
|
||||
struct ALsourceProps *first = ATOMIC_LOAD_SEQ(&source->FreeList);
|
||||
do {
|
||||
ATOMIC_STORE(&props->next, first, almemory_order_relaxed);
|
||||
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(struct ALsourceProps*,
|
||||
&source->FreeList, &first, props, almemory_order_acq_rel,
|
||||
almemory_order_acquire) == 0);
|
||||
ATOMIC_REPLACE_HEAD(struct ALsourceProps*, &source->FreeList, props);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -373,6 +373,18 @@ inline uint DecrementRef(RefCount *ptr)
|
||||
{ return ATOMIC_SUB_SEQ(ptr, 1)-1; }
|
||||
|
||||
|
||||
/* WARNING: A livelock is theoretically possible if another thread keeps
|
||||
* changing the head without giving this a chance to actually swap in the new
|
||||
* one (practically impossible with this little code, but...).
|
||||
*/
|
||||
#define ATOMIC_REPLACE_HEAD(T, _head, _entry) do { \
|
||||
T _first = ATOMIC_LOAD(_head, almemory_order_acquire); \
|
||||
do { \
|
||||
ATOMIC_STORE(&(_entry)->next, _first, almemory_order_relaxed); \
|
||||
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(T, _head, &_first, _entry, \
|
||||
almemory_order_acq_rel, almemory_order_acquire) == 0); \
|
||||
} while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user