8 #include <condition_variable>
11 #include <unordered_map>
13 #include <rapidsmpf/communicator/communicator.hpp>
14 #include <rapidsmpf/pausable_thread_loop.hpp>
15 #include <rapidsmpf/statistics.hpp>
83 [[nodiscard]] constexpr
bool is_valid()
const {
131 Duration sleep = std::chrono::microseconds{1}
195 std::shared_ptr<Statistics> statistics_;
196 bool is_thread_initialized_{
false};
198 mutable std::mutex mutex_;
199 std::condition_variable cv_;
201 std::unordered_map<FunctionIndex, FunctionState> functions_;
A logger base class for handling different levels of log messages.
Store state of a function.
FunctionState(Function &&function)
Construct state of a function.
bool is_done
Whether the function has completed.
void operator()()
Execute the function.
A progress thread that can execute arbitrary functions.
FunctionID add_function(Function &&function)
Insert a function to process as part of the event loop.
bool is_running() const
Check if the progress thread is currently running.
void pause()
Pause the progress thread.
void resume()
Resume the progress thread.
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.
void remove_function(FunctionID function_id)
Remove a function and stop processing it as part of the event loop.
void stop()
Stop the thread, blocking until all functions are done.
std::uint64_t FunctionIndex
The sequential index of a function within a ProgressThread.
std::function< ProgressState()> Function
The function type supported by ProgressThread, returning the progress state of the function.
std::uintptr_t ProgressThreadAddress
The address of a ProgressThread instance.
ProgressState
The progress state of a function, can be either InProgress or Done.
static std::shared_ptr< Statistics > disabled()
Returns a shared pointer to a disabled (no-op) Statistics instance.
A thread loop that can be paused, resumed, and stopped.
The unique ID of a function registered with ProgressThread. Composed of the ProgressThread address an...
FunctionID()=default
Construct a FunctionID with an invalid address.
constexpr FunctionID(ProgressThreadAddress thread_addr, FunctionIndex index)
Construct a new FunctionID.
constexpr bool is_valid() const
Check if the FunctionID is valid.
FunctionIndex function_index
The sequential index of the function.
ProgressThreadAddress thread_address
The address of the ProgressThread instance.