#ifndef LOGOS_PLAIN_IO_CONTEXT_POOL_H #define LOGOS_PLAIN_IO_CONTEXT_POOL_H #include #include #include #include namespace logos::plain { // ----------------------------------------------------------------------------- // IoContextPool — owns a single boost::asio::io_context and a worker thread // that runs it until the pool is destroyed. // // One pool per SDK process is sufficient for our traffic (a handful of // concurrent connections). If we ever need more parallelism, swap for a // multi-thread pool (one io_context per thread + round-robin dispatch). // // Access the shared pool via `sharedPool()`; tests / special cases can // construct their own. // ----------------------------------------------------------------------------- class IoContextPool { public: IoContextPool(); ~IoContextPool(); IoContextPool(const IoContextPool&) = delete; IoContextPool& operator=(const IoContextPool&) = delete; boost::asio::io_context& ioContext() { return m_ioc; } // Process-wide default pool. Thread-safe lazy init. static IoContextPool& shared(); private: boost::asio::io_context m_ioc; boost::asio::executor_work_guard m_guard; std::thread m_worker; }; } // namespace logos::plain #endif // LOGOS_PLAIN_IO_CONTEXT_POOL_H