aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
Diffstat (limited to 'alc')
-rw-r--r--alc/context.cpp177
-rw-r--r--alc/context.h62
2 files changed, 17 insertions, 222 deletions
diff --git a/alc/context.cpp b/alc/context.cpp
index 1c6d026a..ec4e9182 100644
--- a/alc/context.cpp
+++ b/alc/context.cpp
@@ -287,158 +287,23 @@ public:
}; // ContextException
-} // namespace
-
-
-ALCcontext::SourceListIterator::SourceListIterator(
- SourceList& sources,
- SourceListIteratorBeginTag) noexcept
- :
- sub_list_iterator_{sources.begin()},
- sub_list_end_iterator_{sources.end()},
- sub_list_item_index_{}
+template<typename F>
+void ForEachSource(ALCcontext *context, F func)
{
- // Search for first non-free item.
- //
- while (true)
+ for(auto &sublist : context->mSourceList)
{
- if (sub_list_iterator_ == sub_list_end_iterator_)
- {
- // End of list.
-
- sub_list_item_index_ = 0;
- return;
- }
-
- if ((~sub_list_iterator_->FreeMask) == 0_u64)
- {
- // All sub-list's items are free.
-
- ++sub_list_iterator_;
- sub_list_item_index_ = 0;
- continue;
- }
-
- if (sub_list_item_index_ >= 64_u64)
- {
- // Sub-list item's index beyond the last one.
-
- ++sub_list_iterator_;
- sub_list_item_index_ = 0;
- continue;
- }
-
- if ((sub_list_iterator_->FreeMask & (1_u64 << sub_list_item_index_)) == 0_u64)
- {
- // Found non-free item.
-
- break;
- }
-
- sub_list_item_index_ += 1;
- }
-}
-
-ALCcontext::SourceListIterator::SourceListIterator(
- SourceList& sources,
- SourceListIteratorEndTag) noexcept
- :
- sub_list_iterator_{sources.end()},
- sub_list_end_iterator_{sources.end()},
- sub_list_item_index_{}
-{
-}
-
-ALCcontext::SourceListIterator::SourceListIterator(
- const SourceListIterator& rhs)
- :
- sub_list_iterator_{rhs.sub_list_iterator_},
- sub_list_end_iterator_{rhs.sub_list_end_iterator_},
- sub_list_item_index_{rhs.sub_list_item_index_}
-{
-}
-
-ALCcontext::SourceListIterator& ALCcontext::SourceListIterator::operator++()
-{
- while (true)
- {
- if (sub_list_iterator_ == sub_list_end_iterator_)
- {
- // End of list.
-
- sub_list_item_index_ = 0;
- break;
- }
-
- if ((~sub_list_iterator_->FreeMask) == 0_u64)
- {
- // All sub-list's items are free.
-
- ++sub_list_iterator_;
- sub_list_item_index_ = 0;
- continue;
- }
-
- sub_list_item_index_ += 1;
-
- if (sub_list_item_index_ >= 64_u64)
- {
- // Sub-list item's index beyond the last one.
-
- ++sub_list_iterator_;
- sub_list_item_index_ = 0;
- continue;
- }
-
- if ((sub_list_iterator_->FreeMask & (1_u64 << sub_list_item_index_)) == 0_u64)
+ uint64_t usemask{~sublist.FreeMask};
+ while(usemask)
{
- // Found non-free item.
+ const int idx{al::countr_zero(usemask)};
+ usemask &= ~(1_u64 << idx);
- break;
+ func(sublist.Sources[idx]);
}
}
-
- return *this;
-}
-
-ALsource& ALCcontext::SourceListIterator::operator*() noexcept
-{
- assert(sub_list_iterator_ != sub_list_end_iterator_);
- return (*sub_list_iterator_).Sources[sub_list_item_index_];
-}
-
-bool ALCcontext::SourceListIterator::operator==(
- const SourceListIterator& rhs) const noexcept
-{
- return
- sub_list_iterator_ == rhs.sub_list_iterator_ &&
- sub_list_end_iterator_ == rhs.sub_list_end_iterator_ &&
- sub_list_item_index_ == rhs.sub_list_item_index_;
-}
-
-bool ALCcontext::SourceListIterator::operator!=(
- const SourceListIterator& rhs) const noexcept
-{
- return !((*this) == rhs);
}
-
-ALCcontext::SourceListEnumerator::SourceListEnumerator(
- ALCcontext::SourceList& sources) noexcept
- :
- sources_{sources}
-{
-}
-
-ALCcontext::SourceListIterator ALCcontext::SourceListEnumerator::begin() noexcept
-{
- return SourceListIterator{sources_, SourceListIteratorBeginTag{}};
-}
-
-ALCcontext::SourceListIterator ALCcontext::SourceListEnumerator::end() noexcept
-{
- return SourceListIterator{sources_, SourceListIteratorEndTag{}};
-}
+} // namespace
bool ALCcontext::eax_is_capable() const noexcept
@@ -546,17 +411,13 @@ ALenum ALCcontext::eax_eax_get(
void ALCcontext::eax_update_filters()
{
- for (auto& source : SourceListEnumerator{mSourceList})
- {
- source.eax_update_filters();
- }
+ ForEachSource(this, std::mem_fn(&ALsource::eax_update_filters));
}
void ALCcontext::eax_commit_and_update_sources()
{
std::unique_lock<std::mutex> source_lock{mSourceLock};
- for (auto& source : SourceListEnumerator{mSourceList})
- source.eax_commit_and_update();
+ ForEachSource(this, std::mem_fn(&ALsource::eax_commit_and_update));
}
void ALCcontext::eax_set_last_error() noexcept
@@ -944,21 +805,17 @@ void ALCcontext::eax_initialize_fx_slots()
void ALCcontext::eax_initialize_sources()
{
std::unique_lock<std::mutex> source_lock{mSourceLock};
-
- for (auto& source : SourceListEnumerator{mSourceList})
- {
- source.eax_initialize(this);
- }
+ auto init_source = [this](ALsource &source) noexcept
+ { source.eax_initialize(this); };
+ ForEachSource(this, init_source);
}
void ALCcontext::eax_update_sources()
{
std::unique_lock<std::mutex> source_lock{mSourceLock};
-
- for (auto& source : SourceListEnumerator{mSourceList})
- {
- source.eax_update(eax_context_shared_dirty_flags_);
- }
+ auto update_source = [this](ALsource &source)
+ { source.eax_update(eax_context_shared_dirty_flags_); };
+ ForEachSource(this, update_source);
}
void ALCcontext::eax_validate_primary_fx_slot_id(
diff --git a/alc/context.h b/alc/context.h
index 0a884835..a7bbef83 100644
--- a/alc/context.h
+++ b/alc/context.h
@@ -260,68 +260,6 @@ public:
private:
- using SourceList = al::vector<SourceSubList>;
-
-
- struct SourceListIteratorBeginTag{};
- struct SourceListIteratorEndTag{};
-
- class SourceListIterator
- {
- public:
- SourceListIterator(
- SourceList& sources,
- SourceListIteratorBeginTag) noexcept;
-
- SourceListIterator(
- SourceList& sources,
- SourceListIteratorEndTag) noexcept;
-
- SourceListIterator(
- const SourceListIterator& rhs);
-
- SourceListIterator& operator=(
- const SourceListIterator& rhs) = delete;
-
- SourceListIterator& operator++();
-
- ALsource& operator*() noexcept;
-
- bool operator==(
- const SourceListIterator& rhs) const noexcept;
-
- bool operator!=(
- const SourceListIterator& rhs) const noexcept;
-
-
- private:
- SourceList::iterator sub_list_iterator_;
- SourceList::iterator sub_list_end_iterator_;
- std::uint64_t sub_list_item_index_;
- }; // SourceListIterator
-
- class SourceListEnumerator
- {
- public:
- explicit SourceListEnumerator(
- SourceList& sources) noexcept;
-
- SourceListEnumerator(
- const SourceListEnumerator& rhs) = delete;
-
- SourceListEnumerator& operator=(
- const SourceListEnumerator& rhs) = delete;
-
- SourceListIterator begin() noexcept;
-
- SourceListIterator end() noexcept;
-
-
- private:
- SourceList& sources_;
- }; // SourceListEnumerator
-
-
struct Eax
{
EAX50CONTEXTPROPERTIES context{};