aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/ALc.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-01-27 01:51:01 -0800
committerChris Robinson <[email protected]>2018-01-27 01:51:01 -0800
commit9613b4bfe24cbefba0f4c9c738ebd30d4b116970 (patch)
tree99c21c7dd7834f8bc9b44db7801e2d77c1df4030 /Alc/ALc.c
parent5d2196c119f376ca6e58e23b43d4ffbaf4c68c12 (diff)
Use a different method for storing and looking up buffers
Rather than each buffer being individually allocated with a generated 'thunk' ID that's used with a uint:ptr map, buffers are allocated in arrays of 64 within a vector. Each group of 64 has an associated 64-bit mask indicating which are free to use, and the buffer ID is comprised of the two array indices which directly locate the buffer (no searching, binary or otherwise). Currently no buffers are actually deallocated after being allocated, though they are reused. So an app that creates a ton of buffers once, then deletes them all and uses only a couple from then on, will have a bit of waste, while an app that's more consistent with the number of used buffers won't be a problem. This can be improved by removing elements of the containing vector that contain all-free buffers while there are plenty of other free buffers. Also, this method can easily be applied to other resources, like sources.
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r--Alc/ALc.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 255265b5..aea49070 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -2376,13 +2376,12 @@ static ALCvoid FreeDevice(ALCdevice *device)
almtx_destroy(&device->BackendLock);
- if(device->BufferMap.size > 0)
- {
- WARN("(%p) Deleting %d Buffer%s\n", device, device->BufferMap.size,
- (device->BufferMap.size==1)?"":"s");
- ReleaseALBuffers(device);
- }
- ResetUIntMap(&device->BufferMap);
+ ReleaseALBuffers(device);
+#define FREE_BUFFERSUBLIST(x) al_free((x)->Buffers)
+ VECTOR_FOR_EACH(BufferSubList, device->BufferList, FREE_BUFFERSUBLIST);
+#undef FREE_BUFFERSUBLIST
+ VECTOR_DEINIT(device->BufferList);
+ almtx_destroy(&device->BufferLock);
if(device->EffectMap.size > 0)
{
@@ -3988,7 +3987,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
device->AuxiliaryEffectSlotMax = 64;
device->NumAuxSends = DEFAULT_SENDS;
- InitUIntMap(&device->BufferMap, INT_MAX);
+ VECTOR_INIT(device->BufferList);
InitUIntMap(&device->EffectMap, INT_MAX);
InitUIntMap(&device->FilterMap, INT_MAX);
@@ -4120,6 +4119,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
return NULL;
}
almtx_init(&device->BackendLock, almtx_plain);
+ almtx_init(&device->BufferLock, almtx_plain);
if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "ambi-format", &fmt))
{
@@ -4265,7 +4265,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
device->RealOut.Buffer = NULL;
device->RealOut.NumChannels = 0;
- InitUIntMap(&device->BufferMap, INT_MAX);
+ VECTOR_INIT(device->BufferList);
InitUIntMap(&device->EffectMap, INT_MAX);
InitUIntMap(&device->FilterMap, INT_MAX);
@@ -4314,6 +4314,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
return NULL;
}
almtx_init(&device->BackendLock, almtx_plain);
+ almtx_init(&device->BufferLock, almtx_plain);
{
ALCdevice *head = ATOMIC_LOAD_SEQ(&DeviceList);
@@ -4488,7 +4489,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
device->AuxiliaryEffectSlotMax = 64;
device->NumAuxSends = DEFAULT_SENDS;
- InitUIntMap(&device->BufferMap, INT_MAX);
+ VECTOR_INIT(device->BufferList);
InitUIntMap(&device->EffectMap, INT_MAX);
InitUIntMap(&device->FilterMap, INT_MAX);
@@ -4508,6 +4509,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
return NULL;
}
almtx_init(&device->BackendLock, almtx_plain);
+ almtx_init(&device->BufferLock, almtx_plain);
//Set output format
device->NumUpdates = 0;