diff options
author | Chris Robinson <[email protected]> | 2014-09-03 16:29:17 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-09-03 16:29:17 -0700 |
commit | 2f2768e7c3a7e0dd5d926ea1eafb7313a58a07d9 (patch) | |
tree | eddd9846a1d55838d6c566b03f9bb542c2f1c69e /OpenAL32 | |
parent | 30e01a7dba78826ab4b0099a313c6f8a46656e42 (diff) |
Make the fontsound's buffer and link fields atomic
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alMidi.h | 5 | ||||
-rw-r--r-- | OpenAL32/alFontsound.c | 30 | ||||
-rw-r--r-- | OpenAL32/alSoundfont.c | 7 |
3 files changed, 25 insertions, 17 deletions
diff --git a/OpenAL32/Include/alMidi.h b/OpenAL32/Include/alMidi.h index 9d9fa6c4..b1c08e40 100644 --- a/OpenAL32/Include/alMidi.h +++ b/OpenAL32/Include/alMidi.h @@ -34,7 +34,7 @@ typedef struct ALenvelope { typedef struct ALfontsound { RefCount ref; - struct ALbuffer *Buffer; + ATOMIC(struct ALbuffer*) Buffer; ALint MinKey, MaxKey; ALint MinVelocity, MaxVelocity; @@ -85,7 +85,8 @@ typedef struct ALfontsound { ALubyte PitchKey; ALbyte PitchCorrection; ALenum SampleType; - struct ALfontsound *Link; + + ATOMIC(struct ALfontsound*) Link; /* NOTE: Each map entry contains *four* (4) ALsfmodulator objects. */ UIntMap ModulatorMap; diff --git a/OpenAL32/alFontsound.c b/OpenAL32/alFontsound.c index 3a8f1460..069fedd3 100644 --- a/OpenAL32/alFontsound.c +++ b/OpenAL32/alFontsound.c @@ -252,6 +252,8 @@ AL_API void AL_APIENTRY alGetFontsoundivSOFT(ALuint id, ALenum param, ALint *val ALCdevice *device; ALCcontext *context; const ALfontsound *sound; + ALfontsound *link; + ALbuffer *buffer; context = GetContextRef(); if(!context) return; @@ -262,7 +264,8 @@ AL_API void AL_APIENTRY alGetFontsoundivSOFT(ALuint id, ALenum param, ALint *val switch(param) { case AL_BUFFER: - values[0] = (sound->Buffer ? sound->Buffer->id : 0); + buffer = ATOMIC_LOAD(&sound->Buffer); + values[0] = (buffer ? buffer->id : 0); break; case AL_MOD_LFO_TO_PITCH_SOFT: @@ -439,7 +442,8 @@ AL_API void AL_APIENTRY alGetFontsoundivSOFT(ALuint id, ALenum param, ALint *val break; case AL_FONTSOUND_LINK_SOFT: - values[0] = (sound->Link ? sound->Link->id : 0); + link = ATOMIC_LOAD(&sound->Link); + values[0] = (link ? link->id : 0); break; default: @@ -528,7 +532,7 @@ static void ALfontsound_Construct(ALfontsound *self) { InitRef(&self->ref, 0); - self->Buffer = NULL; + ATOMIC_INIT(&self->Buffer, NULL); self->MinKey = 0; self->MaxKey = 127; @@ -593,7 +597,8 @@ static void ALfontsound_Construct(ALfontsound *self) self->PitchKey = 0; self->PitchCorrection = 0; self->SampleType = AL_MONO_SOFT; - self->Link = NULL; + + ATOMIC_INIT(&self->Link, NULL); InitUIntMap(&self->ModulatorMap, ~0); @@ -602,17 +607,18 @@ static void ALfontsound_Construct(ALfontsound *self) static void ALfontsound_Destruct(ALfontsound *self) { + ALfontsound *link; + ALbuffer *buffer; ALsizei i; FreeThunkEntry(self->id); self->id = 0; - if(self->Buffer) - DecrementRef(&self->Buffer->ref); - self->Buffer = NULL; - if(self->Link) - DecrementRef(&self->Link->ref); - self->Link = NULL; + if((buffer=ATOMIC_EXCHANGE(ALbuffer*, &self->Buffer, NULL)) != NULL) + DecrementRef(&buffer->ref); + + if((link=ATOMIC_EXCHANGE(ALfontsound*, &self->Link, NULL)) != NULL) + DecrementRef(&link->ref); for(i = 0;i < self->ModulatorMap.size;i++) { @@ -641,7 +647,7 @@ void ALfontsound_setPropi(ALfontsound *self, ALCcontext *context, ALenum param, } if(buffer) IncrementRef(&buffer->ref); - if((buffer=ExchangePtr((XchgPtr*)&self->Buffer, buffer)) != NULL) + if((buffer=ATOMIC_EXCHANGE(ALbuffer*, &self->Buffer, buffer)) != NULL) DecrementRef(&buffer->ref); break; @@ -832,7 +838,7 @@ void ALfontsound_setPropi(ALfontsound *self, ALCcontext *context, ALenum param, SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE); if(link) IncrementRef(&link->ref); - if((link=ExchangePtr((XchgPtr*)&self->Link, link)) != NULL) + if((link=ATOMIC_EXCHANGE(ALfontsound*, &self->Link, link)) != NULL) DecrementRef(&link->ref); break; diff --git a/OpenAL32/alSoundfont.c b/OpenAL32/alSoundfont.c index 30c97a3a..44f5c35c 100644 --- a/OpenAL32/alSoundfont.c +++ b/OpenAL32/alSoundfont.c @@ -395,10 +395,11 @@ void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device) { if(sounds[j] && ReadRef(&sounds[j]->ref) == 0) { + ALbuffer *buffer; + deleting = AL_TRUE; - if(sounds[j]->Buffer) + if((buffer=ATOMIC_LOAD(&sounds[j]->Buffer)) != NULL) { - ALbuffer *buffer = sounds[j]->Buffer; ALbuffer **iter; #define MATCH_BUFFER(_i) (buffer == *(_i)) @@ -423,8 +424,8 @@ void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device) DeleteBuffer(device, *(iter)); \ } while(0) VECTOR_FOR_EACH(ALbuffer*, buffers, DELETE_BUFFER); - VECTOR_DEINIT(buffers); #undef DELETE_BUFFER + VECTOR_DEINIT(buffers); } |