aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2024-01-01 05:11:53 -0800
committerChris Robinson <[email protected]>2024-01-01 05:53:12 -0800
commit45fca6a301a6d424bd0d856d0ae29ce56c5dc9ac (patch)
tree483daf3d82c03da685650840261cddded6c493cb /al
parent2f2edb326128c56e269a171961d991d8d7936e4f (diff)
Use an allocator to allocate uninitilized sublists
Diffstat (limited to 'al')
-rw-r--r--al/auxeffectslot.cpp31
-rw-r--r--al/buffer.cpp31
-rw-r--r--al/effect.cpp31
-rw-r--r--al/filter.cpp31
-rw-r--r--al/source.cpp31
5 files changed, 79 insertions, 76 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp
index d95748d7..5eea3425 100644
--- a/al/auxeffectslot.cpp
+++ b/al/auxeffectslot.cpp
@@ -53,6 +53,8 @@
namespace {
+using SubListAllocator = typename al::allocator<std::array<ALeffectslot,64>>;
+
struct FactoryItem {
EffectSlotType Type;
EffectStateFactory* (&GetFactory)();
@@ -238,22 +240,21 @@ bool EnsureEffectSlots(ALCcontext *context, size_t needed)
[](size_t cur, const EffectSlotSubList &sublist) noexcept -> size_t
{ return cur + static_cast<ALuint>(al::popcount(sublist.FreeMask)); })};
- while(needed > count)
- {
- if(context->mEffectSlotList.size() >= 1<<25) UNLIKELY
- return false;
-
- context->mEffectSlotList.emplace_back();
- auto sublist = context->mEffectSlotList.end() - 1;
- sublist->FreeMask = ~0_u64;
- sublist->EffectSlots = static_cast<gsl::owner<std::array<ALeffectslot,64>*>>(
- al_calloc(alignof(ALeffectslot), sizeof(*sublist->EffectSlots)));
- if(!sublist->EffectSlots) UNLIKELY
+ try {
+ while(needed > count)
{
- context->mEffectSlotList.pop_back();
- return false;
+ if(context->mEffectSlotList.size() >= 1<<25) UNLIKELY
+ return false;
+
+ EffectSlotSubList sublist{};
+ sublist.FreeMask = ~0_u64;
+ sublist.EffectSlots = SubListAllocator{}.allocate(1);
+ context->mEffectSlotList.emplace_back(std::move(sublist));
+ count += 64;
}
- count += 64;
+ }
+ catch(...) {
+ return false;
}
return true;
}
@@ -1004,7 +1005,7 @@ EffectSlotSubList::~EffectSlotSubList()
usemask &= ~(1_u64 << idx);
}
FreeMask = ~usemask;
- al_free(alignof(ALeffectslot), EffectSlots);
+ SubListAllocator{}.deallocate(EffectSlots, 1);
EffectSlots = nullptr;
}
diff --git a/al/buffer.cpp b/al/buffer.cpp
index 646ec8ea..2aafbf2d 100644
--- a/al/buffer.cpp
+++ b/al/buffer.cpp
@@ -68,6 +68,8 @@
namespace {
+using SubListAllocator = typename al::allocator<std::array<ALbuffer,64>>;
+
std::optional<AmbiLayout> AmbiLayoutFromEnum(ALenum layout)
{
switch(layout)
@@ -178,22 +180,21 @@ bool EnsureBuffers(ALCdevice *device, size_t needed)
[](size_t cur, const BufferSubList &sublist) noexcept -> size_t
{ return cur + static_cast<ALuint>(al::popcount(sublist.FreeMask)); })};
- while(needed > count)
- {
- if(device->BufferList.size() >= 1<<25) UNLIKELY
- return false;
-
- device->BufferList.emplace_back();
- auto sublist = device->BufferList.end() - 1;
- sublist->FreeMask = ~0_u64;
- sublist->Buffers = static_cast<gsl::owner<std::array<ALbuffer,64>*>>(al_calloc(
- alignof(ALbuffer), sizeof(*sublist->Buffers)));
- if(!sublist->Buffers) UNLIKELY
+ try {
+ while(needed > count)
{
- device->BufferList.pop_back();
- return false;
+ if(device->BufferList.size() >= 1<<25) UNLIKELY
+ return false;
+
+ BufferSubList sublist{};
+ sublist.FreeMask = ~0_u64;
+ sublist.Buffers = SubListAllocator{}.allocate(1);
+ device->BufferList.emplace_back(std::move(sublist));
+ count += 64;
}
- count += 64;
+ }
+ catch(...) {
+ return false;
}
return true;
}
@@ -1490,7 +1491,7 @@ BufferSubList::~BufferSubList()
usemask &= ~(1_u64 << idx);
}
FreeMask = ~usemask;
- al_free(alignof(ALbuffer), Buffers);
+ SubListAllocator{}.deallocate(Buffers, 1);
Buffers = nullptr;
}
diff --git a/al/effect.cpp b/al/effect.cpp
index 2f5422fd..071b32c6 100644
--- a/al/effect.cpp
+++ b/al/effect.cpp
@@ -89,6 +89,8 @@ effect_exception::~effect_exception() = default;
namespace {
+using SubListAllocator = typename al::allocator<std::array<ALeffect,64>>;
+
auto GetDefaultProps(ALenum type) -> const EffectProps&
{
switch(type)
@@ -126,22 +128,21 @@ bool EnsureEffects(ALCdevice *device, size_t needed)
[](size_t cur, const EffectSubList &sublist) noexcept -> size_t
{ return cur + static_cast<ALuint>(al::popcount(sublist.FreeMask)); })};
- while(needed > count)
- {
- if(device->EffectList.size() >= 1<<25) UNLIKELY
- return false;
-
- device->EffectList.emplace_back();
- auto sublist = device->EffectList.end() - 1;
- sublist->FreeMask = ~0_u64;
- sublist->Effects = static_cast<gsl::owner<std::array<ALeffect,64>*>>(al_calloc(
- alignof(ALeffect), sizeof(*sublist->Effects)));
- if(!sublist->Effects) UNLIKELY
+ try {
+ while(needed > count)
{
- device->EffectList.pop_back();
- return false;
+ if(device->EffectList.size() >= 1<<25) UNLIKELY
+ return false;
+
+ EffectSubList sublist{};
+ sublist.FreeMask = ~0_u64;
+ sublist.Effects = SubListAllocator{}.allocate(1);
+ device->EffectList.emplace_back(std::move(sublist));
+ count += 64;
}
- count += 64;
+ }
+ catch(...) {
+ return false;
}
return true;
}
@@ -572,7 +573,7 @@ EffectSubList::~EffectSubList()
usemask &= ~(1_u64 << idx);
}
FreeMask = ~usemask;
- al_free(alignof(ALeffect), Effects);
+ SubListAllocator{}.deallocate(Effects, 1);
Effects = nullptr;
}
diff --git a/al/filter.cpp b/al/filter.cpp
index b67a65f7..528d6059 100644
--- a/al/filter.cpp
+++ b/al/filter.cpp
@@ -49,6 +49,8 @@
namespace {
+using SubListAllocator = typename al::allocator<std::array<ALfilter,64>>;
+
class filter_exception final : public al::base_exception {
ALenum mErrorCode;
@@ -121,22 +123,21 @@ bool EnsureFilters(ALCdevice *device, size_t needed)
[](size_t cur, const FilterSubList &sublist) noexcept -> size_t
{ return cur + static_cast<ALuint>(al::popcount(sublist.FreeMask)); })};
- while(needed > count)
- {
- if(device->FilterList.size() >= 1<<25) UNLIKELY
- return false;
-
- device->FilterList.emplace_back();
- auto sublist = device->FilterList.end() - 1;
- sublist->FreeMask = ~0_u64;
- sublist->Filters = static_cast<gsl::owner<std::array<ALfilter,64>*>>(al_calloc(
- alignof(ALfilter), sizeof(*sublist->Filters)));
- if(!sublist->Filters) UNLIKELY
+ try {
+ while(needed > count)
{
- device->FilterList.pop_back();
- return false;
+ if(device->FilterList.size() >= 1<<25) UNLIKELY
+ return false;
+
+ FilterSubList sublist{};
+ sublist.FreeMask = ~0_u64;
+ sublist.Filters = SubListAllocator{}.allocate(1);
+ device->FilterList.emplace_back(std::move(sublist));
+ count += 64;
}
- count += 64;
+ }
+ catch(...) {
+ return false;
}
return true;
}
@@ -700,6 +701,6 @@ FilterSubList::~FilterSubList()
usemask &= ~(1_u64 << idx);
}
FreeMask = ~usemask;
- al_free(alignof(ALfilter), Filters);
+ SubListAllocator{}.deallocate(Filters, 1);
Filters = nullptr;
}
diff --git a/al/source.cpp b/al/source.cpp
index 425acbfa..27144389 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -80,7 +80,7 @@
namespace {
-using namespace std::placeholders;
+using SubListAllocator = typename al::allocator<std::array<ALsource,64>>;
using std::chrono::nanoseconds;
using seconds_d = std::chrono::duration<double>;
@@ -721,22 +721,21 @@ bool EnsureSources(ALCcontext *context, size_t needed)
[](size_t cur, const SourceSubList &sublist) noexcept -> size_t
{ return cur + static_cast<ALuint>(al::popcount(sublist.FreeMask)); })};
- while(needed > count)
- {
- if(context->mSourceList.size() >= 1<<25) UNLIKELY
- return false;
-
- context->mSourceList.emplace_back();
- auto sublist = context->mSourceList.end() - 1;
- sublist->FreeMask = ~0_u64;
- sublist->Sources = static_cast<gsl::owner<std::array<ALsource,64>*>>(al_calloc(
- alignof(ALsource), sizeof(*sublist->Sources)));
- if(!sublist->Sources) UNLIKELY
+ try {
+ while(needed > count)
{
- context->mSourceList.pop_back();
- return false;
+ if(context->mSourceList.size() >= 1<<25) UNLIKELY
+ return false;
+
+ SourceSubList sublist{};
+ sublist.FreeMask = ~0_u64;
+ sublist.Sources = SubListAllocator{}.allocate(1);
+ context->mSourceList.emplace_back(std::move(sublist));
+ count += 64;
}
- count += 64;
+ }
+ catch(...) {
+ return false;
}
return true;
}
@@ -3643,7 +3642,7 @@ SourceSubList::~SourceSubList()
std::destroy_at(al::to_address(Sources->begin() + idx));
}
FreeMask = ~usemask;
- al_free(alignof(ALsource), Sources);
+ SubListAllocator{}.deallocate(Sources, 1);
Sources = nullptr;
}