Use generic atomics in more places
This commit is contained in:
@@ -718,12 +718,12 @@ static const ALchar alExtList[] =
|
||||
"AL_SOFT_loop_points AL_SOFT_MSADPCM AL_SOFT_source_latency "
|
||||
"AL_SOFT_source_length";
|
||||
|
||||
static volatile ALCenum LastNullDeviceError = ALC_NO_ERROR;
|
||||
static ATOMIC(ALCenum) LastNullDeviceError = ATOMIC_INIT_STATIC(ALC_NO_ERROR);
|
||||
|
||||
/* Thread-local current context */
|
||||
static altss_t LocalContext;
|
||||
/* Process-wide current context */
|
||||
static ALCcontext *volatile GlobalContext = NULL;
|
||||
static ATOMIC(ALCcontext*) GlobalContext = ATOMIC_INIT_STATIC(NULL);
|
||||
|
||||
/* Mixing thread piority level */
|
||||
ALint RTPrioLevel;
|
||||
@@ -1558,9 +1558,9 @@ static void alcSetError(ALCdevice *device, ALCenum errorCode)
|
||||
}
|
||||
|
||||
if(device)
|
||||
device->LastError = errorCode;
|
||||
ATOMIC_STORE(device->LastError, errorCode);
|
||||
else
|
||||
LastNullDeviceError = errorCode;
|
||||
ATOMIC_STORE(LastNullDeviceError, errorCode);
|
||||
}
|
||||
|
||||
|
||||
@@ -1895,7 +1895,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
RestoreFPUMode(&oldMode);
|
||||
return ALC_INVALID_DEVICE;
|
||||
}
|
||||
slot->NeedsUpdate = AL_FALSE;
|
||||
ATOMIC_STORE(slot->NeedsUpdate, AL_FALSE);
|
||||
V(slot->EffectState,update)(device, slot);
|
||||
}
|
||||
UnlockUIntMapRead(&context->EffectSlotMap);
|
||||
@@ -1946,7 +1946,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
RestoreFPUMode(&oldMode);
|
||||
return ALC_INVALID_DEVICE;
|
||||
}
|
||||
slot->NeedsUpdate = AL_FALSE;
|
||||
ATOMIC_STORE(slot->NeedsUpdate, AL_FALSE);
|
||||
V(slot->EffectState,update)(device, slot);
|
||||
}
|
||||
ALCdevice_Unlock(device);
|
||||
@@ -2110,7 +2110,7 @@ static ALvoid InitContext(ALCcontext *Context)
|
||||
Context->Listener->Params.Velocity[i] = 0.0f;
|
||||
|
||||
//Validate Context
|
||||
Context->LastError = AL_NO_ERROR;
|
||||
ATOMIC_STORE_UNSAFE(Context->LastError, AL_NO_ERROR);
|
||||
ATOMIC_STORE_UNSAFE(Context->UpdateSources, AL_FALSE);
|
||||
Context->ActiveSourceCount = 0;
|
||||
InitUIntMap(&Context->SourceMap, Context->Device->MaxNoOfSources);
|
||||
@@ -2189,7 +2189,7 @@ static void ReleaseContext(ALCcontext *context, ALCdevice *device)
|
||||
ALCcontext_DecRef(context);
|
||||
}
|
||||
|
||||
if(CompExchangePtr((XchgPtr*)&GlobalContext, context, NULL) == context)
|
||||
if(ATOMIC_COMPARE_EXCHANGE(ALCcontext*, GlobalContext, context, NULL) == context)
|
||||
ALCcontext_DecRef(context);
|
||||
|
||||
ALCdevice_Lock(device);
|
||||
@@ -2272,7 +2272,7 @@ ALCcontext *GetContextRef(void)
|
||||
else
|
||||
{
|
||||
LockLists();
|
||||
context = GlobalContext;
|
||||
context = ATOMIC_LOAD(GlobalContext);
|
||||
if(context)
|
||||
ALCcontext_IncRef(context);
|
||||
UnlockLists();
|
||||
@@ -2296,11 +2296,11 @@ ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
|
||||
|
||||
if(VerifyDevice(device))
|
||||
{
|
||||
errorCode = ExchangeInt(&device->LastError, ALC_NO_ERROR);
|
||||
errorCode = ATOMIC_EXCHANGE(ALCenum, device->LastError, ALC_NO_ERROR);
|
||||
ALCdevice_DecRef(device);
|
||||
}
|
||||
else
|
||||
errorCode = ExchangeInt(&LastNullDeviceError, ALC_NO_ERROR);
|
||||
errorCode = ATOMIC_EXCHANGE(ALCenum, LastNullDeviceError, ALC_NO_ERROR);
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
@@ -2854,7 +2854,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device->LastError = ALC_NO_ERROR;
|
||||
ATOMIC_STORE(device->LastError, ALC_NO_ERROR);
|
||||
|
||||
if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR)
|
||||
{
|
||||
@@ -2952,11 +2952,8 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
|
||||
*/
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
Context = altss_get(LocalContext);
|
||||
if(!Context) Context = GlobalContext;
|
||||
|
||||
ALCcontext *Context = altss_get(LocalContext);
|
||||
if(!Context) Context = ATOMIC_LOAD(GlobalContext);
|
||||
return Context;
|
||||
}
|
||||
|
||||
@@ -2966,9 +2963,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
|
||||
*/
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
Context = altss_get(LocalContext);
|
||||
return Context;
|
||||
return altss_get(LocalContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -2986,7 +2981,7 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
return ALC_FALSE;
|
||||
}
|
||||
/* context's reference count is already incremented */
|
||||
context = ExchangePtr((XchgPtr*)&GlobalContext, context);
|
||||
context = ATOMIC_EXCHANGE(ALCcontext*, GlobalContext, context);
|
||||
if(context) ALCcontext_DecRef(context);
|
||||
|
||||
if((context=altss_get(LocalContext)) != NULL)
|
||||
@@ -3073,7 +3068,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
InitRef(&device->ref, 1);
|
||||
device->Connected = ALC_TRUE;
|
||||
device->Type = Playback;
|
||||
device->LastError = ALC_NO_ERROR;
|
||||
ATOMIC_STORE_UNSAFE(device->LastError, ALC_NO_ERROR);
|
||||
|
||||
device->Flags = 0;
|
||||
device->Bs2b = NULL;
|
||||
@@ -3539,7 +3534,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
|
||||
InitRef(&device->ref, 1);
|
||||
device->Connected = ALC_TRUE;
|
||||
device->Type = Loopback;
|
||||
device->LastError = ALC_NO_ERROR;
|
||||
ATOMIC_STORE_UNSAFE(device->LastError, ALC_NO_ERROR);
|
||||
|
||||
device->Flags = 0;
|
||||
device->Bs2b = NULL;
|
||||
|
||||
@@ -1202,7 +1202,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
|
||||
slot_end = VECTOR_ITER_END(ctx->ActiveAuxSlots);
|
||||
while(slot != slot_end)
|
||||
{
|
||||
if(!DeferUpdates && ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE))
|
||||
if(!DeferUpdates && ATOMIC_EXCHANGE(ALenum, (*slot)->NeedsUpdate, AL_FALSE))
|
||||
V((*slot)->EffectState,update)(device, *slot);
|
||||
|
||||
V((*slot)->EffectState,process)(SamplesToDo, (*slot)->WetBuffer[0],
|
||||
@@ -1220,7 +1220,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
|
||||
slot = &device->DefaultSlot;
|
||||
if(*slot != NULL)
|
||||
{
|
||||
if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE))
|
||||
if(ATOMIC_EXCHANGE(ALenum, (*slot)->NeedsUpdate, AL_FALSE))
|
||||
V((*slot)->EffectState,update)(device, *slot);
|
||||
|
||||
V((*slot)->EffectState,process)(SamplesToDo, (*slot)->WetBuffer[0],
|
||||
|
||||
@@ -71,7 +71,7 @@ typedef struct ALeffectslot {
|
||||
volatile ALfloat Gain;
|
||||
volatile ALboolean AuxSendAuto;
|
||||
|
||||
volatile ALenum NeedsUpdate;
|
||||
ATOMIC(ALenum) NeedsUpdate;
|
||||
ALeffectState *EffectState;
|
||||
|
||||
alignas(16) ALfloat WetBuffer[1][BUFFERSIZE];
|
||||
|
||||
@@ -621,7 +621,7 @@ struct ALCdevice_struct
|
||||
|
||||
al_string DeviceName;
|
||||
|
||||
volatile ALCenum LastError;
|
||||
ATOMIC(ALCenum) LastError;
|
||||
|
||||
// Maximum number of sources that can be created
|
||||
ALuint MaxNoOfSources;
|
||||
@@ -746,7 +746,7 @@ struct ALCcontext_struct
|
||||
UIntMap SourceMap;
|
||||
UIntMap EffectSlotMap;
|
||||
|
||||
volatile ALenum LastError;
|
||||
ATOMIC(ALenum) LastError;
|
||||
|
||||
ATOMIC(ALenum) UpdateSources;
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param
|
||||
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
|
||||
|
||||
slot->Gain = value;
|
||||
slot->NeedsUpdate = AL_TRUE;
|
||||
ATOMIC_STORE(slot->NeedsUpdate, AL_TRUE);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -485,7 +485,7 @@ ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *e
|
||||
/* FIXME: This should be done asynchronously, but since the EffectState
|
||||
* object was changed, it needs an update before its Process method can
|
||||
* be called. */
|
||||
EffectSlot->NeedsUpdate = AL_FALSE;
|
||||
ATOMIC_STORE(EffectSlot->NeedsUpdate, AL_FALSE);
|
||||
V(EffectSlot->EffectState,update)(Device, EffectSlot);
|
||||
ALCdevice_Unlock(Device);
|
||||
|
||||
@@ -501,7 +501,7 @@ ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *e
|
||||
ALCdevice_Lock(Device);
|
||||
memcpy(&EffectSlot->EffectProps, &effect->Props, sizeof(effect->Props));
|
||||
ALCdevice_Unlock(Device);
|
||||
EffectSlot->NeedsUpdate = AL_TRUE;
|
||||
ATOMIC_STORE(EffectSlot->NeedsUpdate, AL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +522,7 @@ ALenum InitEffectSlot(ALeffectslot *slot)
|
||||
|
||||
slot->Gain = 1.0;
|
||||
slot->AuxSendAuto = AL_TRUE;
|
||||
slot->NeedsUpdate = AL_FALSE;
|
||||
ATOMIC_STORE_UNSAFE(slot->NeedsUpdate, AL_FALSE);
|
||||
for(c = 0;c < 1;c++)
|
||||
{
|
||||
for(i = 0;i < BUFFERSIZE;i++)
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ ALvoid alSetError(ALCcontext *Context, ALenum errorCode)
|
||||
raise(SIGTRAP);
|
||||
#endif
|
||||
}
|
||||
CompExchangeInt(&Context->LastError, AL_NO_ERROR, errorCode);
|
||||
ATOMIC_COMPARE_EXCHANGE(ALenum, Context->LastError, AL_NO_ERROR, errorCode);
|
||||
}
|
||||
|
||||
AL_API ALenum AL_APIENTRY alGetError(void)
|
||||
@@ -68,7 +68,7 @@ AL_API ALenum AL_APIENTRY alGetError(void)
|
||||
return AL_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
errorCode = ExchangeInt(&Context->LastError, AL_NO_ERROR);
|
||||
errorCode = ATOMIC_EXCHANGE(ALenum, Context->LastError, AL_NO_ERROR);
|
||||
|
||||
ALCcontext_DecRef(Context);
|
||||
|
||||
|
||||
+1
-1
@@ -752,7 +752,7 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
|
||||
slot_end = VECTOR_ITER_END(context->ActiveAuxSlots);
|
||||
while(slot != slot_end)
|
||||
{
|
||||
if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE))
|
||||
if(ATOMIC_EXCHANGE(ALenum, (*slot)->NeedsUpdate, AL_FALSE))
|
||||
V((*slot)->EffectState,update)(context->Device, *slot);
|
||||
slot++;
|
||||
}
|
||||
|
||||
+18
-23
@@ -10,53 +10,48 @@
|
||||
|
||||
/* A simple spinlock. Yield the thread while the given integer is set by
|
||||
* another. Could probably be improved... */
|
||||
static void Lock(volatile int *l)
|
||||
{
|
||||
while(ExchangeInt(l, true) == true)
|
||||
althrd_yield();
|
||||
}
|
||||
|
||||
static void Unlock(volatile int *l)
|
||||
{
|
||||
ExchangeInt(l, false);
|
||||
}
|
||||
#define LOCK(l) do { \
|
||||
while(ATOMIC_EXCHANGE(int, (l), true) == true) \
|
||||
althrd_yield(); \
|
||||
} while(0)
|
||||
#define UNLOCK(l) ATOMIC_STORE(l, false)
|
||||
|
||||
|
||||
void RWLockInit(RWLock *lock)
|
||||
{
|
||||
InitRef(&lock->read_count, 0);
|
||||
InitRef(&lock->write_count, 0);
|
||||
lock->read_lock = false;
|
||||
lock->read_entry_lock = false;
|
||||
lock->write_lock = false;
|
||||
ATOMIC_STORE_UNSAFE(lock->read_lock, false);
|
||||
ATOMIC_STORE_UNSAFE(lock->read_entry_lock, false);
|
||||
ATOMIC_STORE_UNSAFE(lock->write_lock, false);
|
||||
}
|
||||
|
||||
void ReadLock(RWLock *lock)
|
||||
{
|
||||
Lock(&lock->read_entry_lock);
|
||||
Lock(&lock->read_lock);
|
||||
LOCK(lock->read_entry_lock);
|
||||
LOCK(lock->read_lock);
|
||||
if(IncrementRef(&lock->read_count) == 1)
|
||||
Lock(&lock->write_lock);
|
||||
Unlock(&lock->read_lock);
|
||||
Unlock(&lock->read_entry_lock);
|
||||
LOCK(lock->write_lock);
|
||||
UNLOCK(lock->read_lock);
|
||||
UNLOCK(lock->read_entry_lock);
|
||||
}
|
||||
|
||||
void ReadUnlock(RWLock *lock)
|
||||
{
|
||||
if(DecrementRef(&lock->read_count) == 0)
|
||||
Unlock(&lock->write_lock);
|
||||
UNLOCK(lock->write_lock);
|
||||
}
|
||||
|
||||
void WriteLock(RWLock *lock)
|
||||
{
|
||||
if(IncrementRef(&lock->write_count) == 1)
|
||||
Lock(&lock->read_lock);
|
||||
Lock(&lock->write_lock);
|
||||
LOCK(lock->read_lock);
|
||||
LOCK(lock->write_lock);
|
||||
}
|
||||
|
||||
void WriteUnlock(RWLock *lock)
|
||||
{
|
||||
Unlock(&lock->write_lock);
|
||||
UNLOCK(lock->write_lock);
|
||||
if(DecrementRef(&lock->write_count) == 0)
|
||||
Unlock(&lock->read_lock);
|
||||
UNLOCK(lock->read_lock);
|
||||
}
|
||||
|
||||
+6
-4
@@ -11,11 +11,13 @@ extern "C" {
|
||||
typedef struct {
|
||||
RefCount read_count;
|
||||
RefCount write_count;
|
||||
volatile int read_lock;
|
||||
volatile int read_entry_lock;
|
||||
volatile int write_lock;
|
||||
ATOMIC(int) read_lock;
|
||||
ATOMIC(int) read_entry_lock;
|
||||
ATOMIC(int) write_lock;
|
||||
} RWLock;
|
||||
#define RWLOCK_STATIC_INITIALIZE { ATOMIC_INIT_STATIC(0), ATOMIC_INIT_STATIC(0), false, false, false }
|
||||
#define RWLOCK_STATIC_INITIALIZE { ATOMIC_INIT_STATIC(0), ATOMIC_INIT_STATIC(0), \
|
||||
ATOMIC_INIT_STATIC(false), ATOMIC_INIT_STATIC(false), \
|
||||
ATOMIC_INIT_STATIC(false) }
|
||||
|
||||
void RWLockInit(RWLock *lock);
|
||||
void ReadLock(RWLock *lock);
|
||||
|
||||
Reference in New Issue
Block a user