summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-10-06 06:39:13 -0700
committerChris Robinson <[email protected]>2011-10-06 06:39:13 -0700
commit81133769def858c663718dc3e676d288594e0d66 (patch)
tree47ece23d7143a64c4c08fe109335a59a71fc7077
parenta7d3779dfafbc7b5011ea7d1b252d94daed969f6 (diff)
Return the key's value from the map when it's removed
-rw-r--r--Alc/helpers.c34
-rw-r--r--OpenAL32/Include/alMain.h13
2 files changed, 10 insertions, 37 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 980c0071..f219f4ae 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -391,8 +391,9 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
return AL_NO_ERROR;
}
-void RemoveUIntMapKey(UIntMap *map, ALuint key)
+ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key)
{
+ ALvoid *ptr = NULL;
WriteLock(&map->lock);
if(map->size > 0)
{
@@ -408,6 +409,7 @@ void RemoveUIntMapKey(UIntMap *map, ALuint key)
}
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]));
@@ -415,6 +417,7 @@ void RemoveUIntMapKey(UIntMap *map, ALuint key)
}
}
WriteUnlock(&map->lock);
+ return ptr;
}
ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key)
@@ -439,32 +442,3 @@ 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 a6ef8bb3..8a9e8d59 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -427,9 +427,8 @@ extern UIntMap TlsDestructor;
void InitUIntMap(UIntMap *map, ALsizei limit);
void ResetUIntMap(UIntMap *map);
ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
-void RemoveUIntMapKey(UIntMap *map, ALuint key);
+ALvoid *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); }
@@ -703,9 +702,9 @@ struct ALCdevice_struct
#define LookupBuffer(m, k) ((struct ALbuffer*)LookupUIntMapKey(&(m)->BufferMap, (k)))
#define LookupEffect(m, k) ((struct ALeffect*)LookupUIntMapKey(&(m)->EffectMap, (k)))
#define LookupFilter(m, k) ((struct ALfilter*)LookupUIntMapKey(&(m)->FilterMap, (k)))
-#define RemoveBuffer(m, k) ((struct ALbuffer*)PopUIntMapValue(&(m)->BufferMap, (k)))
-#define RemoveEffect(m, k) ((struct ALeffect*)PopUIntMapValue(&(m)->EffectMap, (k)))
-#define RemoveFilter(m, k) ((struct ALfilter*)PopUIntMapValue(&(m)->FilterMap, (k)))
+#define RemoveBuffer(m, k) ((struct ALbuffer*)RemoveUIntMapKey(&(m)->BufferMap, (k)))
+#define RemoveEffect(m, k) ((struct ALeffect*)RemoveUIntMapKey(&(m)->EffectMap, (k)))
+#define RemoveFilter(m, k) ((struct ALfilter*)RemoveUIntMapKey(&(m)->FilterMap, (k)))
struct ALCcontext_struct
@@ -745,8 +744,8 @@ struct ALCcontext_struct
#define LookupSource(m, k) ((struct ALsource*)LookupUIntMapKey(&(m)->SourceMap, (k)))
#define LookupEffectSlot(m, k) ((struct ALeffectslot*)LookupUIntMapKey(&(m)->EffectSlotMap, (k)))
-#define RemoveSource(m, k) ((struct ALsource*)PopUIntMapValue(&(m)->SourceMap, (k)))
-#define RemoveEffectSlot(m, k) ((struct ALeffectslot*)PopUIntMapValue(&(m)->EffectSlotMap, (k)))
+#define RemoveSource(m, k) ((struct ALsource*)RemoveUIntMapKey(&(m)->SourceMap, (k)))
+#define RemoveEffectSlot(m, k) ((struct ALeffectslot*)RemoveUIntMapKey(&(m)->EffectSlotMap, (k)))
ALCcontext *GetContextRef(void);