1 #include "stg/common.h"
8 EVENT_LOOP& EVENT_LOOP::instance()
14 bool EVENT_LOOP::Start()
16 m_thread = std::jthread([this](auto token){ Run(std::move(token)); });
20 bool EVENT_LOOP::Stop()
22 m_thread.request_stop();
29 void EVENT_LOOP::Run(std::stop_token token)
32 sigfillset(&signalSet);
33 pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
35 printfd(__FILE__, "EVENT_LOOP::Runner - Before start\n");
36 while (!token.stop_requested())
38 // Create new empty actions list
41 std::unique_lock lock(m_mutex);
42 // Check for any actions...
43 // ... and sleep until new actions added
44 printfd(__FILE__, "EVENT_LOOP::Runner - Sleeping until new actions arrived\n");
46 // Check for running after wake up
47 if (token.stop_requested())
48 break; // Don't process any actions if stopping
52 // Fast swap with current
54 // Invoke all current actions
55 printfd(__FILE__, "EVENT_LOOP::Runner - Invoke %d actions\n", local.size());
58 printfd(__FILE__, "EVENT_LOOP::Runner - Before stop\n");