|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Manages io_context execution on shared thread pools. More...
#include <io_context_thread_manager.h>

Classes | |
| class | impl |
| struct | metrics |
| Get current metrics. More... | |
Public Member Functions | |
| std::future< void > | run_io_context (std::shared_ptr< asio::io_context > io_context, const std::string &component_name="") |
| Run an io_context on the shared thread pool. | |
| void | stop_io_context (std::shared_ptr< asio::io_context > io_context) |
| Stop an io_context managed by this manager. | |
| void | stop_all () |
| Stop all managed io_contexts. | |
| void | wait_all () |
| Wait for all managed io_contexts to complete. | |
| size_t | active_count () const |
| Get the number of active io_contexts. | |
| bool | is_active (std::shared_ptr< asio::io_context > io_context) const |
| Check if an io_context is managed and running. | |
| void | set_thread_pool (std::shared_ptr< thread_pool_interface > pool) |
| Set a custom thread pool. | |
| metrics | get_metrics () const |
| Get current metrics. | |
| io_context_thread_manager (size_t worker_count=0) | |
| Construct a manager with specified worker count. | |
| ~io_context_thread_manager () | |
| Destructor - stops the manager if running. | |
| io_context_thread_manager (const io_context_thread_manager &)=delete | |
| io_context_thread_manager & | operator= (const io_context_thread_manager &)=delete |
| io_context_thread_manager (io_context_thread_manager &&) noexcept | |
| io_context_thread_manager & | operator= (io_context_thread_manager &&) noexcept |
| bool | start () |
| Start the io_context worker threads. | |
| void | stop () |
| Stop the io_context and join worker threads. | |
| bool | is_running () const noexcept |
| Check if the manager is running. | |
| asio::io_context & | get_io_context () noexcept |
| Get the managed io_context. | |
| size_t | worker_count () const noexcept |
| Get the number of worker threads. | |
Static Public Member Functions | |
| static io_context_thread_manager & | instance () |
| Get the singleton instance. | |
Private Member Functions | |
| io_context_thread_manager () | |
| ~io_context_thread_manager () | |
| io_context_thread_manager (const io_context_thread_manager &)=delete | |
| io_context_thread_manager & | operator= (const io_context_thread_manager &)=delete |
| io_context_thread_manager (io_context_thread_manager &&)=delete | |
| io_context_thread_manager & | operator= (io_context_thread_manager &&)=delete |
Private Attributes | |
| std::shared_ptr< impl > | pimpl_ |
| PIMPL pointer with intentional leak pattern. | |
| std::unique_ptr< asio::io_context > | io_context_ |
| std::unique_ptr< asio::executor_work_guard< asio::io_context::executor_type > > | work_guard_ |
| std::vector< std::thread > | workers_ |
| std::atomic< bool > | running_ {false} |
| size_t | worker_count_ |
| std::mutex | mutex_ |
Manages io_context execution on shared thread pools.
Manages ASIO io_context lifecycle and worker threads.
This class provides unified thread management for all asio::io_context instances in the network system. Instead of each component managing its own threads, this manager provides a centralized approach.
All public methods are thread-safe.
This class provides a thread-safe wrapper around asio::io_context, managing worker threads for asynchronous I/O operations.
|
private |
Definition at line 233 of file io_context_thread_manager.cpp.
|
privatedefault |
|
privatedelete |
|
privatedelete |
|
explicitexport |
Construct a manager with specified worker count.
| worker_count | Number of worker threads (0 = hardware concurrency) |
|
export |
Destructor - stops the manager if running.
|
exportdelete |
|
exportnoexcept |
| size_t kcenon::network::integration::io_context_thread_manager::active_count | ( | ) | const |
Get the number of active io_contexts.
Definition at line 264 of file io_context_thread_manager.cpp.
References pimpl_.
|
exportnoexcept |
Get the managed io_context.
| io_context_thread_manager::metrics kcenon::network::integration::io_context_thread_manager::get_metrics | ( | ) | const |
Get current metrics.
Definition at line 280 of file io_context_thread_manager.cpp.
References pimpl_.
|
static |
Get the singleton instance.
Definition at line 228 of file io_context_thread_manager.cpp.
References instance().
Referenced by kcenon::network::core::messaging_client::do_start_impl(), kcenon::network::core::messaging_server::do_start_impl(), kcenon::network::core::messaging_client::do_stop_impl(), kcenon::network::core::messaging_server::do_stop_impl(), and instance().


| bool kcenon::network::integration::io_context_thread_manager::is_active | ( | std::shared_ptr< asio::io_context > | io_context | ) | const |
Check if an io_context is managed and running.
| io_context | The io_context to check |
Definition at line 268 of file io_context_thread_manager.cpp.
References pimpl_.
|
exportnoexcept |
Check if the manager is running.
|
privatedelete |
|
exportdelete |
|
exportnoexcept |
|
privatedelete |
| std::future< void > kcenon::network::integration::io_context_thread_manager::run_io_context | ( | std::shared_ptr< asio::io_context > | io_context, |
| const std::string & | component_name = "" ) |
Run an io_context on the shared thread pool.
Submits the io_context::run() call as a task to the thread pool. The io_context will run until stopped or an error occurs.
| io_context | The io_context to run |
| component_name | Optional name for logging/identification |
Definition at line 243 of file io_context_thread_manager.cpp.
References pimpl_.
Referenced by kcenon::network::core::messaging_client::do_start_impl(), and kcenon::network::core::messaging_server::do_start_impl().

| void kcenon::network::integration::io_context_thread_manager::set_thread_pool | ( | std::shared_ptr< thread_pool_interface > | pool | ) |
Set a custom thread pool.
By default, uses the thread pool from network_context. This allows using a different thread pool if needed.
| pool | The thread pool to use |
Definition at line 274 of file io_context_thread_manager.cpp.
References pimpl_.
|
export |
Start the io_context worker threads.
|
export |
Stop the io_context and join worker threads.
| void kcenon::network::integration::io_context_thread_manager::stop_all | ( | ) |
Stop all managed io_contexts.
Stops all io_contexts that were started via run_io_context(). Useful for application shutdown.
Definition at line 256 of file io_context_thread_manager.cpp.
References pimpl_.
| void kcenon::network::integration::io_context_thread_manager::stop_io_context | ( | std::shared_ptr< asio::io_context > | io_context | ) |
Stop an io_context managed by this manager.
Calls io_context::stop() to terminate the run loop. The future returned by run_io_context() will complete after this.
| io_context | The io_context to stop |
Definition at line 250 of file io_context_thread_manager.cpp.
References pimpl_.
Referenced by kcenon::network::core::messaging_client::do_stop_impl(), and kcenon::network::core::messaging_server::do_stop_impl().

| void kcenon::network::integration::io_context_thread_manager::wait_all | ( | ) |
Wait for all managed io_contexts to complete.
Blocks until all io_context::run() calls have returned. Should be called after stop_all() for clean shutdown.
Definition at line 260 of file io_context_thread_manager.cpp.
References pimpl_.
|
exportnoexcept |
Get the number of worker threads.
|
exportprivate |
|
mutableexportprivate |
|
private |
PIMPL pointer with intentional leak pattern.
Uses shared_ptr with no-op deleter to prevent heap corruption during static destruction. This is intentional - see docs/DESIGN_DECISIONS.md for detailed rationale.
Definition at line 181 of file io_context_thread_manager.h.
Referenced by active_count(), get_metrics(), is_active(), run_io_context(), set_thread_pool(), stop_all(), stop_io_context(), and wait_all().
|
exportprivate |
|
exportprivate |
|
exportprivate |
|
exportprivate |