From ee60248d19a087b27e3dfd170cbd92768dae75d5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 30 Aug 2011 00:33:01 -0700 Subject: Lock the context while deleting sources only as needed --- OpenAL32/alSource.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'OpenAL32') diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 1ce6b95f..a0988e5d 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -127,7 +127,6 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) alSetError(Context, AL_INVALID_VALUE); else { - LockContext(Context); // Check that all Sources are valid (and can therefore be deleted) for(i = 0;i < n;i++) { @@ -142,22 +141,32 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) // All Sources are valid, and can be deleted for(i = 0;i < n;i++) { + ALsource **srclist, **srclistend; + + LockContext(Context); if((Source=LookupSource(Context->SourceMap, sources[i])) == NULL) + { + UnlockContext(Context); continue; + } // Remove Source from list of Sources RemoveUIntMapKey(&Context->SourceMap, Source->source); FreeThunkEntry(Source->source); - for(j = 0;j < Context->ActiveSourceCount;j++) + srclist = Context->ActiveSources; + srclistend = srclist + Context->ActiveSourceCount; + while(srclist != srclistend) { - if(Context->ActiveSources[j] == Source) + if(*srclist == Source) { - ALsizei end = --(Context->ActiveSourceCount); - Context->ActiveSources[j] = Context->ActiveSources[end]; + Context->ActiveSourceCount--; + *srclist = *(--srclistend); break; } + srclist++; } + UnlockContext(Context); // For each buffer in the source's queue... while(Source->queue != NULL) @@ -180,7 +189,6 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) memset(Source,0,sizeof(ALsource)); free(Source); } - UnlockContext(Context); } ALCcontext_DecRef(Context); -- cgit v1.2.3