#pragma once #include "ev.hpp" #include "udp_handle.hpp" #include #include #include #include #include #include #include #include #include namespace llarp::uv { class UVWakeup; class UVRepeater; class Loop : public llarp::EventLoop { public: using Callback = std::function; Loop(size_t queue_size); virtual void run() override; bool running() const override; llarp_time_t time_now() const override { return m_Impl->now(); } void call_later(llarp_time_t delay_ms, std::function callback) override; void tick_event_loop(); void stop() override; bool add_ticker(std::function ticker) override; bool add_network_interface( std::shared_ptr netif, std::function handler) override; void call_soon(std::function f) override; std::shared_ptr make_waker(std::function callback) override; std::shared_ptr make_repeater() override; virtual std::shared_ptr make_udp(UDPReceiveFunc on_recv) override; void FlushLogic(); std::shared_ptr MaybeGetUVWLoop() override; bool inEventLoop() const override; protected: std::shared_ptr m_Impl; std::optional m_EventLoopThreadID; private: std::shared_ptr m_WakeUp; std::atomic m_Run; using AtomicQueue_t = llarp::thread::Queue>; AtomicQueue_t m_LogicCalls; #ifdef LOKINET_DEBUG uint64_t last_time; uint64_t loop_run_count; #endif std::atomic m_nextID; std::map m_pendingCalls; std::unordered_map> m_Polls; void wakeup() override; }; } // namespace llarp::uv