Add functions to retrieve the source from the source map while removing it
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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); }
|
||||
|
||||
+5
-8
@@ -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);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove Source from list of Sources
|
||||
RemoveUIntMapKey(&Context->SourceMap, Source->source);
|
||||
if((Source=RemoveSource(Context->SourceMap, sources[i])) == NULL)
|
||||
continue;
|
||||
|
||||
FreeThunkEntry(Source->source);
|
||||
|
||||
LockContext(Context);
|
||||
srclist = Context->ActiveSources;
|
||||
srclistend = srclist + Context->ActiveSourceCount;
|
||||
while(srclist != srclistend)
|
||||
|
||||
Reference in New Issue
Block a user