diff options
-rw-r--r-- | Alc/midi/fluidsynth.c | 6 | ||||
-rw-r--r-- | OpenAL32/Include/alMidi.h | 5 | ||||
-rw-r--r-- | OpenAL32/alFontsound.c | 30 | ||||
-rw-r--r-- | OpenAL32/alSoundfont.c | 7 |
4 files changed, 29 insertions, 19 deletions
diff --git a/Alc/midi/fluidsynth.c b/Alc/midi/fluidsynth.c index 82159127..bf774ab1 100644 --- a/Alc/midi/fluidsynth.c +++ b/Alc/midi/fluidsynth.c @@ -247,6 +247,8 @@ typedef struct FSample { static void FSample_Construct(FSample *self, ALfontsound *sound) { fluid_sample_t *sample = STATIC_CAST(fluid_sample_t, self); + ALbuffer *buffer = ATOMIC_LOAD(&sound->Buffer); + memset(sample->name, 0, sizeof(sample->name)); sample->start = sound->Start; sample->end = sound->End; @@ -256,8 +258,8 @@ static void FSample_Construct(FSample *self, ALfontsound *sound) sample->origpitch = sound->PitchKey; sample->pitchadj = sound->PitchCorrection; sample->sampletype = getSampleType(sound->SampleType); - sample->valid = !!sound->Buffer; - sample->data = sound->Buffer ? sound->Buffer->data : NULL; + sample->valid = !!buffer; + sample->data = buffer ? buffer->data : NULL; sample->amplitude_that_reaches_noise_floor_is_valid = 0; sample->amplitude_that_reaches_noise_floor = 0.0; 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); } |