A pool of IoContext objects, representing and managing CPU resources of the system. More...
#include <io_context_pool.h>
Public Types | |
using | io_context = ::boost::asio::io_context |
Public Member Functions | |
IoContextPool (const IoContextPool &)=delete | |
void | operator= (const IoContextPool &)=delete |
IoContextPool (std::size_t pool_size=0, std::vector< size_t > cpus={}) | |
void | Run () |
Starts running all IoContext objects in the pool. Does not block. | |
void | Stop () |
Stops all io_context objects in the pool. More... | |
IoContext & | GetNextContext () |
Get an io_context to use. Thread-safe. | |
IoContext & | operator[] (size_t i) |
IoContext & | at (size_t i) |
size_t | size () const |
template<typename Func , AcceptArgsCheck< Func, IoContext & > = 0> | |
void | AsyncOnAll (Func &&func) |
Runs func in all IO threads asynchronously. More... | |
template<typename Func , AcceptArgsCheck< Func, unsigned, IoContext & > = 0> | |
void | AsyncOnAll (Func &&func) |
Runs func in all IO threads asynchronously. More... | |
template<typename Func , AcceptArgsCheck< Func, IoContext & > = 0> | |
void | AwaitOnAll (Func &&func) |
Runs the funcion in all IO threads asynchronously. Blocks until all the asynchronous calls return. More... | |
template<typename Func , AcceptArgsCheck< Func, unsigned, IoContext & > = 0> | |
void | AwaitOnAll (Func &&func) |
Blocks until all the asynchronous calls to func return. Func receives both the index and IoContext&. func must not block. More... | |
template<typename Func , AcceptArgsCheck< Func, unsigned, IoContext & > = 0> | |
void | AsyncFiberOnAll (Func &&func) |
Runs func in a fiber asynchronously. func must accept IoContext&. func may fiber-block. More... | |
template<typename Func , AcceptArgsCheck< Func, IoContext & > = 0> | |
void | AsyncFiberOnAll (Func &&func) |
Runs func in a fiber asynchronously. func must accept IoContext&. func may fiber-block. More... | |
template<typename Func , AcceptArgsCheck< Func, unsigned, IoContext & > = 0> | |
void | AwaitFiberOnAll (Func &&func) |
Runs func wrapped in fiber on all IO threads in parallel. func must accept IoContext&. func may fiber-block. More... | |
template<typename Func , AcceptArgsCheck< Func, IoContext & > = 0> | |
void | AwaitFiberOnAll (Func &&func) |
Runs func wrapped in fiber on all IO threads in parallel. func must accept IoContext&. func may fiber-block. More... | |
template<typename Func > | |
void | AwaitFiberOnAllSerially (Func &&func) |
Runs func wrapped in fiber on all IO threads, SERIALLY. func must accept IoContext&. func may fiber-block. More... | |
IoContext * | GetThisContext () |
A pool of IoContext objects, representing and managing CPU resources of the system.
The main entry for launching asynchronous processes across all IO threads. For single thread manager see IoContext class.
Definition at line 26 of file io_context_pool.h.
|
explicit |
Constructs io_context pool with number of threads equal to 'pool_size'. pool_size = 0 chooses automatically pool size equal to number of cores in the system.
|
inline |
Runs func
in a fiber asynchronously. func must accept IoContext&. func may fiber-block.
func | 'func' callback runs inside a wrapping fiber. |
Definition at line 133 of file io_context_pool.h.
|
inline |
Runs func
in a fiber asynchronously. func must accept IoContext&. func may fiber-block.
func | 'func' callback runs inside a wrapping fiber. |
Definition at line 147 of file io_context_pool.h.
|
inline |
Runs func in all IO threads asynchronously.
The task must be CPU-only non IO-blocking code because it runs directly in IO-fiber. MapTask runs asynchronously and will exit before the task finishes. The 'func' must accept IoContext& as its argument.
Definition at line 67 of file io_context_pool.h.
|
inline |
Runs func in all IO threads asynchronously.
The task must be CPU-only non IO-blocking code because it runs directly in IO-fiber. MapTask runs asynchronously and will exit before the task finishes. The 'func' must accept unsigned int (io context index) and IoContext& as its arguments.
Definition at line 84 of file io_context_pool.h.
|
inline |
Runs func
wrapped in fiber on all IO threads in parallel. func must accept IoContext&. func may fiber-block.
func | Waits for all the callbacks to finish. |
Definition at line 162 of file io_context_pool.h.
|
inline |
Runs func
wrapped in fiber on all IO threads in parallel. func must accept IoContext&. func may fiber-block.
func | Waits for all the callbacks to finish. |
Definition at line 180 of file io_context_pool.h.
|
inline |
Runs func
wrapped in fiber on all IO threads, SERIALLY. func must accept IoContext&. func may fiber-block.
Note that this function is highly inefficient, it is mostly useful when one wants to reduce several thread-local variables into a single common variable. Instead of creating a mutex for the variable, it is better to just run sequentially.
Definition at line 198 of file io_context_pool.h.
|
inline |
Runs the funcion in all IO threads asynchronously. Blocks until all the asynchronous calls return.
Func must accept "IoContext&" and it should not block.
Definition at line 99 of file io_context_pool.h.
|
inline |
Blocks until all the asynchronous calls to func return. Func receives both the index and IoContext&. func must not block.
Definition at line 115 of file io_context_pool.h.
void util::IoContextPool::Stop | ( | ) |
Stops all io_context objects in the pool.
Waits for all the threads to finish. Requires that Run has been called. Blocks the current thread until all the pool threads exited.
Definition at line 84 of file io_context_pool.cc.