From 6967a31450441fc5605c05db6f65505dace4b263 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 8 Jun 2024 10:07:59 +0200 Subject: wayland/core: move to new impl (#6268) * wayland/core/dmabuf: move to new impl it's the final countdown --- src/helpers/signal/Signal.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/helpers/signal/Signal.cpp') diff --git a/src/helpers/signal/Signal.cpp b/src/helpers/signal/Signal.cpp index fdd2cc23..fd2d11c8 100644 --- a/src/helpers/signal/Signal.cpp +++ b/src/helpers/signal/Signal.cpp @@ -2,19 +2,40 @@ #include void CSignal::emit(std::any data) { - bool dirty = false; + bool dirty = false; + std::vector> listeners; for (auto& l : m_vListeners) { - if (const CHyprSignalListener L = l.lock()) - L->emit(data); - else + if (l.expired()) { dirty = true; + continue; + } + + listeners.emplace_back(l.lock()); } + std::vector statics; for (auto& l : m_vStaticListeners) { + statics.emplace_back(l.get()); + } + + for (auto& l : listeners) { + // if there is only one lock, it means the event is only held by the listeners + // vector and was removed during our iteration + if (l.strongRef() == 1) { + dirty = true; + continue; + } l->emit(data); } + for (auto& l : statics) { + l->emit(data); + } + + // release SPs + listeners.clear(); + if (dirty) std::erase_if(m_vListeners, [](const auto& other) { return other.expired(); }); } -- cgit v1.2.3