aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/helpers.c29
-rw-r--r--OpenAL32/Include/alMain.h1
-rw-r--r--OpenAL32/alSource.c11
3 files changed, 34 insertions, 7 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 90bec01c..8aa13111 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -431,3 +431,32 @@ ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key)
ReadUnlock(&map->lock);
return ptr;
}
+
+ALvoid *PopUIntMapValue(UIntMap *map, ALuint key)
+{
+ ALvoid *ptr = NULL;
+ WriteLock(&map->lock);
+ if(map->size > 0)
+ {
+ ALsizei low = 0;
+ ALsizei high = map->size - 1;
+ while(low < high)
+ {
+ ALsizei mid = low + (high-low)/2;
+ if(map->array[mid].key < key)
+ low = mid + 1;
+ else
+ high = mid;
+ }
+ if(map->array[low].key == key)
+ {
+ ptr = map->array[low].value;
+ if(low < map->size-1)
+ memmove(&map->array[low], &map->array[low+1],
+ (map->size-1-low)*sizeof(map->array[0]));
+ map->size--;
+ }
+ }
+ WriteUnlock(&map->lock);
+ return ptr;
+}
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 57eee33d..cd4b7174 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -343,6 +343,7 @@ void ResetUIntMap(UIntMap *map);
ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
void RemoveUIntMapKey(UIntMap *map, ALuint key);
ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
+ALvoid *PopUIntMapValue(UIntMap *map, ALuint key);
static __inline void LockUIntMapRead(UIntMap *map)
{ ReadLock(&map->lock); }
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index a0988e5d..e45cbcd9 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -51,6 +51,7 @@ static ALvoid GetSourceOffset(ALsource *Source, ALenum eName, ALdouble *Offsets,
static ALint GetByteOffset(ALsource *Source);
#define LookupSource(m, k) ((ALsource*)LookupUIntMapKey(&(m), (k)))
+#define RemoveSource(m, k) ((ALsource*)PopUIntMapValue(&(m), (k)))
#define LookupBuffer(m, k) ((ALbuffer*)LookupUIntMapKey(&(m), (k)))
#define LookupFilter(m, k) ((ALfilter*)LookupUIntMapKey(&(m), (k)))
#define LookupEffectSlot(m, k) ((ALeffectslot*)LookupUIntMapKey(&(m), (k)))
@@ -143,17 +144,13 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
{
ALsource **srclist, **srclistend;
- LockContext(Context);
- if((Source=LookupSource(Context->SourceMap, sources[i])) == NULL)
- {
- UnlockContext(Context);
+ // Remove Source from list of Sources
+ if((Source=RemoveSource(Context->SourceMap, sources[i])) == NULL)
continue;
- }
- // Remove Source from list of Sources
- RemoveUIntMapKey(&Context->SourceMap, Source->source);
FreeThunkEntry(Source->source);
+ LockContext(Context);
srclist = Context->ActiveSources;
srclistend = srclist + Context->ActiveSourceCount;
while(srclist != srclistend)