Remove the pointer-specific atomic exchange macros

This commit is contained in:
Chris Robinson 2018-11-18 03:59:39 -08:00
parent 7433cb5f4c
commit f48be9d73b
7 changed files with 33 additions and 55 deletions

View File

@ -2331,8 +2331,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
* auxiliary sends is changing. Active sources will have updates
* respecified in UpdateAllSourceProps.
*/
vprops = static_cast<ALvoiceProps*>(ATOMIC_EXCHANGE_PTR(&context->FreeVoiceProps,
static_cast<ALvoiceProps*>(nullptr), almemory_order_acq_rel));
vprops = ATOMIC_EXCHANGE(&context->FreeVoiceProps, static_cast<ALvoiceProps*>(nullptr),
almemory_order_acq_rel);
while(vprops)
{
struct ALvoiceProps *next = ATOMIC_LOAD(&vprops->next, almemory_order_relaxed);
@ -2345,8 +2345,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
{
ALvoice *voice = context->Voices[pos];
al_free(ATOMIC_EXCHANGE_PTR(&voice->Update, static_cast<ALvoiceProps*>(nullptr),
almemory_order_acq_rel));
al_free(ATOMIC_EXCHANGE(&voice->Update, static_cast<ALvoiceProps*>(nullptr),
almemory_order_acq_rel));
if(ATOMIC_LOAD(&voice->Source, almemory_order_acquire) == nullptr)
continue;
@ -2711,7 +2711,7 @@ static void FreeContext(ALCcontext *context)
context->DefaultSlot = nullptr;
}
al_free(ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots,
al_free(ATOMIC_EXCHANGE(&context->ActiveAuxSlots,
static_cast<ALeffectslotArray*>(nullptr), almemory_order_relaxed));
ReleaseALSources(context);
@ -2813,7 +2813,7 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device)
V0(device->Backend,lock)();
origctx = context;
newhead = ATOMIC_LOAD(&context->next, almemory_order_relaxed);
if(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&device->ContextList, &origctx, newhead))
if(!ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(&device->ContextList, &origctx, newhead))
{
ALCcontext *list;
do {
@ -2822,7 +2822,7 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device)
*/
list = origctx;
origctx = context;
} while(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&list->next, &origctx, newhead));
} while(!ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(&list->next, &origctx, newhead));
}
else
ret = !!newhead;
@ -3848,8 +3848,8 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
ALCcontext *head = ATOMIC_LOAD_SEQ(&device->ContextList);
do {
ATOMIC_STORE(&ALContext->next, head, almemory_order_relaxed);
} while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK_SEQ(&device->ContextList, &head,
ALContext) == 0);
} while(ATOMIC_COMPARE_EXCHANGE_WEAK_SEQ(&device->ContextList, &head,
ALContext) == 0);
}
almtx_unlock(&device->BackendLock);
@ -4204,7 +4204,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
do {
list = origdev;
origdev = device;
} while(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&list->next, &origdev, nextdev));
} while(!ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(&list->next, &origdev, nextdev));
}
listlock.unlock();
@ -4332,7 +4332,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
do {
list = origdev;
origdev = device;
} while(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&list->next, &origdev, nextdev));
} while(!ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(&list->next, &origdev, nextdev));
}
listlock.unlock();

View File

@ -75,7 +75,7 @@ static HrtfDirectMixerFunc MixDirectHrtf = MixDirectHrtf_C;
void DeinitVoice(ALvoice *voice)
{
al_free(ATOMIC_EXCHANGE_PTR_SEQ(&voice->Update, static_cast<ALvoiceProps*>(nullptr)));
al_free(ATOMIC_EXCHANGE_SEQ(&voice->Update, static_cast<ALvoiceProps*>(nullptr)));
}
@ -315,8 +315,8 @@ static bool CalcContextParams(ALCcontext *Context)
ALlistener &Listener = Context->Listener;
struct ALcontextProps *props;
props = static_cast<ALcontextProps*>(ATOMIC_EXCHANGE_PTR(&Context->Update,
static_cast<ALcontextProps*>(nullptr), almemory_order_acq_rel));
props = ATOMIC_EXCHANGE(&Context->Update, static_cast<ALcontextProps*>(nullptr),
almemory_order_acq_rel);
if(!props) return false;
Listener.Params.MetersPerUnit = props->MetersPerUnit;
@ -341,8 +341,8 @@ static bool CalcListenerParams(ALCcontext *Context)
struct ALlistenerProps *props;
aluVector vel;
props = static_cast<ALlistenerProps*>(ATOMIC_EXCHANGE_PTR(&Listener.Update,
static_cast<ALlistenerProps*>(nullptr), almemory_order_acq_rel));
props = ATOMIC_EXCHANGE(&Listener.Update, static_cast<ALlistenerProps*>(nullptr),
almemory_order_acq_rel);
if(!props) return false;
/* AT then UP */
@ -385,8 +385,8 @@ static bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool f
struct ALeffectslotProps *props;
ALeffectState *state;
props = static_cast<ALeffectslotProps*>(ATOMIC_EXCHANGE_PTR(&slot->Update,
static_cast<ALeffectslotProps*>(nullptr), almemory_order_acq_rel));
props = ATOMIC_EXCHANGE(&slot->Update, static_cast<ALeffectslotProps*>(nullptr),
almemory_order_acq_rel);
if(!props && !force) return false;
if(props)
@ -1455,8 +1455,8 @@ static void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force)
ALbufferlistitem *BufferListItem;
struct ALvoiceProps *props;
props = static_cast<ALvoiceProps*>(ATOMIC_EXCHANGE_PTR(&voice->Update,
static_cast<ALvoiceProps*>(nullptr), almemory_order_acq_rel));
props = ATOMIC_EXCHANGE(&voice->Update, static_cast<ALvoiceProps*>(nullptr),
almemory_order_acq_rel);
if(!props && !force) return;
if(props)
@ -1857,10 +1857,8 @@ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...)
for(i = 0;i < ctx->VoiceCount;i++)
{
ALvoice *voice = ctx->Voices[i];
ALsource *source;
source = static_cast<ALsource*>(ATOMIC_EXCHANGE_PTR(&voice->Source,
static_cast<ALsource*>(nullptr), almemory_order_relaxed));
ALsource *source = ATOMIC_EXCHANGE(&voice->Source, static_cast<ALsource*>(nullptr),
almemory_order_relaxed);
if(source && ATOMIC_LOAD(&voice->Playing, almemory_order_relaxed))
{
/* If the source's voice was playing, it's now effectively

View File

@ -622,8 +622,7 @@ static void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontex
newarray->count = newcount;
}
curarray = static_cast<ALeffectslotArray*>(ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots,
newarray, almemory_order_acq_rel));
curarray = ATOMIC_EXCHANGE(&context->ActiveAuxSlots, newarray, almemory_order_acq_rel);
while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
althrd_yield();
al_free(curarray);
@ -658,8 +657,7 @@ static void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcon
/* TODO: Could reallocate newarray now that we know it's needed size. */
curarray = static_cast<ALeffectslotArray*>(ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots,
newarray, almemory_order_acq_rel));
curarray = ATOMIC_EXCHANGE(&context->ActiveAuxSlots, newarray, almemory_order_acq_rel);
while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
althrd_yield();
al_free(curarray);
@ -728,7 +726,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
struct ALeffectslotProps *next;
do {
next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
} while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeEffectslotProps, &props, next,
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->FreeEffectslotProps, &props, next,
almemory_order_seq_cst, almemory_order_acquire) == 0);
}
@ -746,8 +744,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
props->State = slot->Effect.State;
/* Set the new container for updating internal parameters. */
props = static_cast<ALeffectslotProps*>(ATOMIC_EXCHANGE_PTR(&slot->Update, props,
almemory_order_acq_rel));
props = ATOMIC_EXCHANGE(&slot->Update, props, almemory_order_acq_rel);
if(props)
{
/* If there was an unused update container, put it back in the

View File

@ -469,7 +469,7 @@ void UpdateListenerProps(ALCcontext *context)
struct ALlistenerProps *next;
do {
next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
} while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeListenerProps, &props, next,
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->FreeListenerProps, &props, next,
almemory_order_seq_cst, almemory_order_acquire) == 0);
}
@ -492,8 +492,7 @@ void UpdateListenerProps(ALCcontext *context)
props->Gain = listener->Gain;
/* Set the new container for updating internal parameters. */
props = static_cast<ALlistenerProps*>(ATOMIC_EXCHANGE_PTR(&listener->Update, props,
almemory_order_acq_rel));
props = ATOMIC_EXCHANGE(&listener->Update, props, almemory_order_acq_rel);
if(props)
{
/* If there was an unused update container, put it back in the

View File

@ -3168,7 +3168,7 @@ static void UpdateSourceProps(ALsource *source, ALvoice *voice, ALsizei num_send
struct ALvoiceProps *next;
do {
next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
} while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeVoiceProps, &props, next,
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->FreeVoiceProps, &props, next,
almemory_order_acq_rel, almemory_order_acquire) == 0);
}
@ -3232,8 +3232,7 @@ static void UpdateSourceProps(ALsource *source, ALvoice *voice, ALsizei num_send
}
/* Set the new container for updating internal parameters. */
props = static_cast<ALvoiceProps*>(ATOMIC_EXCHANGE_PTR(&voice->Update, props,
almemory_order_acq_rel));
props = ATOMIC_EXCHANGE(&voice->Update, props, almemory_order_acq_rel);
if(props)
{
/* If there was an unused update container, put it back in the

View File

@ -773,7 +773,7 @@ void UpdateContextProps(ALCcontext *context)
struct ALcontextProps *next;
do {
next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
} while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeContextProps, &props, next,
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->FreeContextProps, &props, next,
almemory_order_seq_cst, almemory_order_acquire) == 0);
}
@ -788,8 +788,7 @@ void UpdateContextProps(ALCcontext *context)
props->mDistanceModel = context->mDistanceModel;
/* Set the new container for updating internal parameters. */
props = static_cast<ALcontextProps*>(ATOMIC_EXCHANGE_PTR(&context->Update, props,
almemory_order_acq_rel));
props = ATOMIC_EXCHANGE(&context->Update, props, almemory_order_acq_rel);
if(props)
{
/* If there was an unused update container, put it back in the

View File

@ -61,14 +61,6 @@ using std::atomic_thread_fence;
#define ATOMIC_THREAD_FENCE atomic_thread_fence
/* If no PTR xchg variants are provided, the normal ones can handle it. */
#ifndef ATOMIC_EXCHANGE_PTR
#define ATOMIC_EXCHANGE_PTR ATOMIC_EXCHANGE
#define ATOMIC_COMPARE_EXCHANGE_PTR_STRONG ATOMIC_COMPARE_EXCHANGE_STRONG
#define ATOMIC_COMPARE_EXCHANGE_PTR_WEAK ATOMIC_COMPARE_EXCHANGE_WEAK
#endif
#define ATOMIC_LOAD_SEQ(_val) ATOMIC_LOAD(_val, almemory_order_seq_cst)
#define ATOMIC_STORE_SEQ(_val, _newval) ATOMIC_STORE(_val, _newval, almemory_order_seq_cst)
@ -81,12 +73,6 @@ using std::atomic_thread_fence;
#define ATOMIC_COMPARE_EXCHANGE_WEAK_SEQ(_val, _oldval, _newval) \
ATOMIC_COMPARE_EXCHANGE_WEAK(_val, _oldval, _newval, almemory_order_seq_cst, almemory_order_seq_cst)
#define ATOMIC_EXCHANGE_PTR_SEQ(_val, _newval) ATOMIC_EXCHANGE_PTR(_val, _newval, almemory_order_seq_cst)
#define ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(_val, _oldval, _newval) \
ATOMIC_COMPARE_EXCHANGE_PTR_STRONG(_val, _oldval, _newval, almemory_order_seq_cst, almemory_order_seq_cst)
#define ATOMIC_COMPARE_EXCHANGE_PTR_WEAK_SEQ(_val, _oldval, _newval) \
ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(_val, _oldval, _newval, almemory_order_seq_cst, almemory_order_seq_cst)
typedef unsigned int uint;
typedef ATOMIC(uint) RefCount;
@ -109,7 +95,7 @@ inline uint DecrementRef(RefCount *ptr)
T _first = ATOMIC_LOAD(_head, almemory_order_acquire); \
do { \
ATOMIC_STORE(&(_entry)->next, _first, almemory_order_relaxed); \
} while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(_head, &_first, _entry, \
} while(ATOMIC_COMPARE_EXCHANGE_WEAK(_head, &_first, _entry, \
almemory_order_acq_rel, almemory_order_acquire) == 0); \
} while(0)