Do an atomic compare-exchange on the global context when destroying a context
This commit is contained in:
parent
108b43458f
commit
9080d5fda0
@ -2147,17 +2147,14 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
|
||||
}
|
||||
UnlockDevice(Device);
|
||||
|
||||
if(CompExchangePtr((void**)&GlobalContext, context, NULL))
|
||||
ALCcontext_DecRef(context);
|
||||
|
||||
if(Device->NumContexts == 0)
|
||||
{
|
||||
ALCdevice_StopPlayback(Device);
|
||||
Device->Flags &= ~DEVICE_RUNNING;
|
||||
}
|
||||
|
||||
if(GlobalContext == context)
|
||||
{
|
||||
GlobalContext = NULL;
|
||||
ALCcontext_DecRef(context);
|
||||
}
|
||||
UnlockLists();
|
||||
|
||||
ALCcontext_DecRef(context);
|
||||
|
@ -243,6 +243,10 @@ static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int new
|
||||
{
|
||||
return __sync_bool_compare_and_swap(ptr, oldval, newval);
|
||||
}
|
||||
static __inline ALboolean CompExchangePtr(void *volatile*ptr, void *oldval, void *newval)
|
||||
{
|
||||
return __sync_bool_compare_and_swap(ptr, oldval, newval);
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
@ -274,6 +278,10 @@ static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int new
|
||||
} u = { ptr };
|
||||
return InterlockedCompareExchange(u.l, newval, oldval) == oldval;
|
||||
}
|
||||
static __inline void *CompExchangePtr(void *volatile*ptr, void *oldval, void *newval)
|
||||
{
|
||||
return InterlockedCompareExchangePointer(ptr, newval, oldval);
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
@ -306,6 +314,10 @@ static __inline ALboolean CompExchangeInt(volatile int *ptr, int oldval, int new
|
||||
{
|
||||
return OSAtomicCompareAndSwap32Barrier(oldval, newval, ptr);
|
||||
}
|
||||
static __inline ALboolean CompExchangeInt(void *volatile*ptr, void *oldval, void *newval)
|
||||
{
|
||||
return OSAtomicCompareAndSwapPtrBarrier(oldval, newval, ptr);
|
||||
}
|
||||
|
||||
#else
|
||||
#error "No atomic functions available on this platform!"
|
||||
|
Loading…
Reference in New Issue
Block a user