Replace ATOMIC_REPLACE_HEAD with an inline function
This commit is contained in:
+4
-4
@@ -330,7 +330,7 @@ static bool CalcContextParams(ALCcontext *Context)
|
||||
Listener.Params.SourceDistanceModel = props->SourceDistanceModel;
|
||||
Listener.Params.mDistanceModel = props->mDistanceModel;
|
||||
|
||||
ATOMIC_REPLACE_HEAD(struct ALcontextProps*, &Context->FreeContextProps, props);
|
||||
AtomicReplaceHead(Context->FreeContextProps, props);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ static bool CalcListenerParams(ALCcontext *Context)
|
||||
|
||||
Listener.Params.Gain = props->Gain * Context->GainBoost;
|
||||
|
||||
ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &Context->FreeListenerProps, props);
|
||||
AtomicReplaceHead(Context->FreeListenerProps, props);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ static bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool f
|
||||
}
|
||||
}
|
||||
|
||||
ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &context->FreeEffectslotProps, props);
|
||||
AtomicReplaceHead(context->FreeEffectslotProps, props);
|
||||
}
|
||||
else
|
||||
state = slot->Params.EffectState;
|
||||
@@ -1465,7 +1465,7 @@ static void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force)
|
||||
FAM_SIZE(struct ALvoiceProps, Send, context->Device->NumAuxSends)
|
||||
);
|
||||
|
||||
ATOMIC_REPLACE_HEAD(struct ALvoiceProps*, &context->FreeVoiceProps, props);
|
||||
AtomicReplaceHead(context->FreeVoiceProps, props);
|
||||
}
|
||||
props = voice->Props;
|
||||
|
||||
|
||||
@@ -730,7 +730,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
|
||||
if(props->State)
|
||||
ALeffectState_DecRef(props->State);
|
||||
props->State = nullptr;
|
||||
ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &context->FreeEffectslotProps, props);
|
||||
AtomicReplaceHead(context->FreeEffectslotProps, props);
|
||||
}
|
||||
|
||||
if(oldstate)
|
||||
|
||||
@@ -498,6 +498,6 @@ void UpdateListenerProps(ALCcontext *context)
|
||||
/* If there was an unused update container, put it back in the
|
||||
* freelist.
|
||||
*/
|
||||
ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &context->FreeListenerProps, props);
|
||||
AtomicReplaceHead(context->FreeListenerProps, props);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3236,7 +3236,7 @@ static void UpdateSourceProps(ALsource *source, ALvoice *voice, ALsizei num_send
|
||||
/* If there was an unused update container, put it back in the
|
||||
* freelist.
|
||||
*/
|
||||
ATOMIC_REPLACE_HEAD(struct ALvoiceProps*, &context->FreeVoiceProps, props);
|
||||
AtomicReplaceHead(context->FreeVoiceProps, props);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -794,6 +794,6 @@ void UpdateContextProps(ALCcontext *context)
|
||||
/* If there was an unused update container, put it back in the
|
||||
* freelist.
|
||||
*/
|
||||
ATOMIC_REPLACE_HEAD(struct ALcontextProps*, &context->FreeContextProps, props);
|
||||
AtomicReplaceHead(context->FreeContextProps, props);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-7
@@ -91,12 +91,14 @@ inline uint DecrementRef(RefCount *ptr)
|
||||
* 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(_head, &_first, _entry, \
|
||||
almemory_order_acq_rel, almemory_order_acquire) == 0); \
|
||||
} while(0)
|
||||
template<typename T>
|
||||
inline void AtomicReplaceHead(std::atomic<T> &head, T newhead)
|
||||
{
|
||||
T first_ = head.load(std::memory_order_acquire);
|
||||
do {
|
||||
newhead->next.store(first_, std::memory_order_relaxed);
|
||||
} while(!head.compare_exchange_weak(first_, newhead,
|
||||
std::memory_order_acq_rel, std::memory_order_acquire));
|
||||
}
|
||||
|
||||
#endif /* AL_ATOMIC_H */
|
||||
|
||||
Reference in New Issue
Block a user