diff options
author | Chris Robinson <[email protected]> | 2011-08-31 01:26:55 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-08-31 02:15:03 -0700 |
commit | 49e2fa428fced4d2ab1e390ad3397dd9e11df960 (patch) | |
tree | ccb86893b1074b02cca71228919b73409e180509 | |
parent | 2fcf97e2077741a878cbe160e7d107e9da0626f2 (diff) |
Avoid the context lock when generating and deleting effects and filters
-rw-r--r-- | OpenAL32/alEffect.c | 30 | ||||
-rw-r--r-- | OpenAL32/alFilter.c | 30 |
2 files changed, 22 insertions, 38 deletions
diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c index c79db1fa..031c86d7 100644 --- a/OpenAL32/alEffect.c +++ b/OpenAL32/alEffect.c @@ -37,13 +37,14 @@ ALboolean DisabledEffects[MAX_EFFECTS]; static void InitEffectParams(ALeffect *effect, ALenum type); #define LookupEffect(m, k) ((ALeffect*)LookupUIntMapKey(&(m), (k))) +#define RemoveEffect(m, k) ((ALeffect*)PopUIntMapValue(&(m), (k))) AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) { ALCcontext *Context; - ALsizei i=0; + ALsizei i; - Context = GetLockedContext(); + Context = GetContextRef(); if(!Context) return; if(n < 0 || IsBadWritePtr((void*)effects, n * sizeof(ALuint))) @@ -53,7 +54,7 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) ALCdevice *device = Context->Device; ALenum err; - while(i < n) + for(i = 0;i < n;i++) { ALeffect *effect = calloc(1, sizeof(ALeffect)); if(!effect) @@ -62,6 +63,7 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) alDeleteEffects(i, effects); break; } + InitEffectParams(effect, AL_EFFECT_NULL); err = NewThunkEntry(&effect->effect); if(err == AL_NO_ERROR) @@ -77,12 +79,11 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) break; } - effects[i++] = effect->effect; - InitEffectParams(effect, AL_EFFECT_NULL); + effects[i] = effect->effect; } } - UnlockContext(Context); + ALCcontext_DecRef(Context); } AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects) @@ -90,19 +91,16 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects) ALCcontext *Context; ALCdevice *device; ALeffect *ALEffect; - ALboolean Failed; ALsizei i; - Context = GetLockedContext(); + Context = GetContextRef(); if(!Context) return; - Failed = AL_TRUE; device = Context->Device; if(n < 0) alSetError(Context, AL_INVALID_VALUE); else { - Failed = AL_FALSE; // Check that all effects are valid for(i = 0;i < n;i++) { @@ -112,22 +110,16 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects) if(LookupEffect(device->EffectMap, effects[i]) == NULL) { alSetError(Context, AL_INVALID_NAME); - Failed = AL_TRUE; + n = 0; break; } } - } - if(!Failed) - { - // All effects are valid for(i = 0;i < n;i++) { // Recheck that the effect is valid, because there could be duplicated names - if((ALEffect=LookupEffect(device->EffectMap, effects[i])) == NULL) + if((ALEffect=RemoveEffect(device->EffectMap, effects[i])) == NULL) continue; - - RemoveUIntMapKey(&device->EffectMap, ALEffect->effect); FreeThunkEntry(ALEffect->effect); memset(ALEffect, 0, sizeof(ALeffect)); @@ -135,7 +127,7 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects) } } - UnlockContext(Context); + ALCcontext_DecRef(Context); } AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect) diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c index a1a810fb..dd338e8d 100644 --- a/OpenAL32/alFilter.c +++ b/OpenAL32/alFilter.c @@ -33,13 +33,14 @@ static void InitFilterParams(ALfilter *filter, ALenum type); #define LookupFilter(m, k) ((ALfilter*)LookupUIntMapKey(&(m), (k))) +#define RemoveFilter(m, k) ((ALfilter*)PopUIntMapValue(&(m), (k))) AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) { ALCcontext *Context; - ALsizei i=0; + ALsizei i; - Context = GetLockedContext(); + Context = GetContextRef(); if(!Context) return; if(n < 0 || IsBadWritePtr((void*)filters, n * sizeof(ALuint))) @@ -49,7 +50,7 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) ALCdevice *device = Context->Device; ALenum err; - while(i < n) + for(i = 0;i < n;i++) { ALfilter *filter = calloc(1, sizeof(ALfilter)); if(!filter) @@ -58,6 +59,7 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) alDeleteFilters(i, filters); break; } + InitFilterParams(filter, AL_FILTER_NULL); err = NewThunkEntry(&filter->filter); if(err == AL_NO_ERROR) @@ -73,12 +75,11 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) break; } - filters[i++] = filter->filter; - InitFilterParams(filter, AL_FILTER_NULL); + filters[i] = filter->filter; } } - UnlockContext(Context); + ALCcontext_DecRef(Context); } AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) @@ -86,19 +87,16 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) ALCcontext *Context; ALCdevice *device; ALfilter *ALFilter; - ALboolean Failed; ALsizei i; - Context = GetLockedContext(); + Context = GetContextRef(); if(!Context) return; - Failed = AL_TRUE; device = Context->Device; if(n < 0) alSetError(Context, AL_INVALID_VALUE); else { - Failed = AL_FALSE; // Check that all filters are valid for(i = 0;i < n;i++) { @@ -108,22 +106,16 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) if(LookupFilter(device->FilterMap, filters[i]) == NULL) { alSetError(Context, AL_INVALID_NAME); - Failed = AL_TRUE; + n = 0; break; } } - } - if(!Failed) - { - // All filters are valid for(i = 0;i < n;i++) { // Recheck that the filter is valid, because there could be duplicated names - if((ALFilter=LookupFilter(device->FilterMap, filters[i])) == NULL) + if((ALFilter=RemoveFilter(device->FilterMap, filters[i])) == NULL) continue; - - RemoveUIntMapKey(&device->FilterMap, ALFilter->filter); FreeThunkEntry(ALFilter->filter); memset(ALFilter, 0, sizeof(ALfilter)); @@ -131,7 +123,7 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters) } } - UnlockContext(Context); + ALCcontext_DecRef(Context); } AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter) |