#ifndef _ASYNCO_ENGINE_ #define _ASYNCO_ENGINE_ #include #include using namespace std; #include namespace marcelb { namespace asynco { #define HW_CONCURRENCY_MINIMAL 4 /** * Internal anonymous class for initializing the ASIO context and thread pool * !!! It is anonymous to protect against use in the initialization of other objects of the same type !!! */ class Engine { public: boost::asio::io_context io_context; void run() { for (auto& runner : runners) { runner.join(); } } private: unique_ptr work { [&] () { return new boost::asio::io_service::work(io_context); } ()}; vector runners { [&] () { vector _runs; unsigned int num_of_runners; #ifdef NUM_OF_RUNNERS num_of_runners = NUM_OF_RUNNERS; #else num_of_runners = thread::hardware_concurrency(); if (num_of_runners < HW_CONCURRENCY_MINIMAL) { num_of_runners = HW_CONCURRENCY_MINIMAL; } #endif for (int i=0; i