Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-12 02:57:35 +03:00
1 parent 2d1d03db1e
commit ef3139ca64
60 files changed
+1774 -4412

No files matched your search

@@ -0,0 +1,42 @@
#include "echoion/standalone/EventCallbackGate.hpp"
#include <Void/Core/Scope.hpp>
#include <utility>
namespace Echoion::Standalone
{
void EventCallbackGate::add(Api::EventCallback callback)
{
std::lock_guard lock(mutex_);
accepting_ = true;
callbacks_.push_back(std::move(callback));
}
void EventCallbackGate::quiesce()
{
std::unique_lock lock(mutex_);
accepting_ = false;
callbacks_.clear();
cv_.wait(lock, [this] { return activeDispatches_ == 0; });
}
void EventCallbackGate::dispatch(const Api::PluginEvent& event)
{
std::vector<Api::EventCallback> callbacks;
{
std::lock_guard lock(mutex_);
if (!accepting_) return;
++activeDispatches_;
callbacks = callbacks_;
}
const auto complete = Void::Scope::on_exit([this] {
std::lock_guard lock(mutex_);
--activeDispatches_;
cv_.notify_all();
});
for (const auto& callback : callbacks) {
if (callback) callback(event);
}
}
}