X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/646c8fd6c0112573ba2aae7f165f5d48e849831e..c59911ca3cd38cf4ab36d2cc62686f97395899f9:/projects/stargazer/eventloop.cpp diff --git a/projects/stargazer/eventloop.cpp b/projects/stargazer/eventloop.cpp deleted file mode 100644 index ea175c41..00000000 --- a/projects/stargazer/eventloop.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "stg/common.h" -#include "eventloop.h" - -#include -#include -#include - -EVENT_LOOP& EVENT_LOOP::instance() -{ - static EVENT_LOOP el; - return el; -} - -bool EVENT_LOOP::Start() -{ -m_thread = std::jthread([this](auto token){ Run(std::move(token)); }); -return false; -} - -bool EVENT_LOOP::Stop() -{ -m_thread.request_stop(); -// Wake up thread -m_cond.notify_all(); -m_thread.join(); -return false; -} - -void EVENT_LOOP::Run(std::stop_token token) -{ -sigset_t signalSet; -sigfillset(&signalSet); -pthread_sigmask(SIG_BLOCK, &signalSet, NULL); - -printfd(__FILE__, "EVENT_LOOP::Runner - Before start\n"); -while (!token.stop_requested()) - { - // Create new empty actions list - ACTIONS_LIST local; - { - std::unique_lock lock(m_mutex); - // Check for any actions... - // ... and sleep until new actions added - printfd(__FILE__, "EVENT_LOOP::Runner - Sleeping until new actions arrived\n"); - m_cond.wait(lock); - // Check for running after wake up - if (token.stop_requested()) - break; // Don't process any actions if stopping - if (!m_list.empty()) - local.swap(m_list); - } - // Fast swap with current - m_list.swap(local); - // Invoke all current actions - printfd(__FILE__, "EVENT_LOOP::Runner - Invoke %d actions\n", local.size()); - local.InvokeAll(); - } -printfd(__FILE__, "EVENT_LOOP::Runner - Before stop\n"); -}