A progress thread that can execute arbitrary functions. More...
#include <progress_thread.hpp>
Classes | |
| struct | FunctionID |
The unique ID of a function registered with ProgressThread. Composed of the ProgressThread address and a sequential function index. More... | |
| class | FunctionState |
| Store state of a function. More... | |
Public Types | |
| enum | ProgressState : bool { InProgress , Done } |
The progress state of a function, can be either InProgress or Done. | |
| using | FunctionIndex = std::uint64_t |
| The sequential index of a function within a ProgressThread. | |
| using | ProgressThreadAddress = std::uintptr_t |
| The address of a ProgressThread instance. | |
| using | Function = std::function< ProgressState()> |
The function type supported by ProgressThread, returning the progress state of the function. | |
Public Member Functions | |
| ProgressThread (Communicator::Logger &logger, std::shared_ptr< Statistics > statistics=Statistics::disabled(), Duration sleep=std::chrono::microseconds{1}) | |
| Construct a new progress thread that can handle multiple functions. More... | |
| void | stop () |
| Stop the thread, blocking until all functions are done. | |
| FunctionID | add_function (Function &&function) |
| Insert a function to process as part of the event loop. More... | |
| void | remove_function (FunctionID function_id) |
| Remove a function and stop processing it as part of the event loop. More... | |
| void | pause () |
| Pause the progress thread. More... | |
| void | resume () |
| Resume the progress thread. | |
| bool | is_running () const |
| Check if the progress thread is currently running. More... | |
A progress thread that can execute arbitrary functions.
Execute each of the registered arbitrary functions in a separate thread. The functions are executed in the order they were registered, and a newly registered function will only execute for the first time in the next iteration of the progress thread.
Definition at line 27 of file progress_thread.hpp.
| rapidsmpf::ProgressThread::ProgressThread | ( | Communicator::Logger & | logger, |
| std::shared_ptr< Statistics > | statistics = Statistics::disabled(), |
||
| Duration | sleep = std::chrono::microseconds{1} |
||
| ) |
Construct a new progress thread that can handle multiple functions.
| logger | The logger instance to use. |
| statistics | The statistics instance to use (disabled by default). |
| sleep | The duration to sleep between each progress loop iteration. If 0, the thread yields execution instead of sleeping. Anecdotally, a 1 us sleep time (the default) is sufficient to avoid starvation and get smooth progress. |
| FunctionID rapidsmpf::ProgressThread::add_function | ( | Function && | function | ) |
Insert a function to process as part of the event loop.
| function | The function to register. |
| bool rapidsmpf::ProgressThread::is_running | ( | ) | const |
Check if the progress thread is currently running.
| void rapidsmpf::ProgressThread::pause | ( | ) |
Pause the progress thread.
| void rapidsmpf::ProgressThread::remove_function | ( | FunctionID | function_id | ) |
Remove a function and stop processing it as part of the event loop.
This function blocks until the function is done (returning ProgressState::Done).
| function_id | The unique function ID returned by add_function. |
| std::logic_error | if the function was not registered with this ProgressThread or was already removed. |