|
#include <ArmarXCore/core/services/tasks/RunningTask.h>
Classes | |
struct | Impl |
Public Types | |
using | CallbackT = std::function< void()> |
Public Member Functions | |
std::string | getName () const |
bool | isFinished () const |
Retrieve finished state of the thread. More... | |
bool | isRunning () const |
Retrieve running state of the thread. More... | |
bool | isStopped () |
Retrieve whether stop() has been called. More... | |
void | join () |
Wait for the RunningTask to finish without telling it to finish. More... | |
RunningTaskBase (std::string const &name) | |
template<typename T > | |
RunningTaskBase (T *parent, void(T::*runningFn)(), const std::string &name="") | |
Constructs a running task within the class parent which calls the runningFn in a new thread. More... | |
void | setName (const std::string &name) |
void | setThreadList (ThreadListPtr threadList) |
void | start () |
Starts the thread. More... | |
void | stop (bool waitForJoin=true) |
Stops the thread. More... | |
bool | waitForFinished (int timeoutMS=-1) |
wait blocking for thread to be finished. More... | |
void | waitForStop () |
Wait blocking for thread until stop() has been called. More... | |
~RunningTaskBase () override | |
Destructor stops the thread and waits for completion. More... | |
Public Attributes | |
CallbackT | callback |
Definition at line 41 of file RunningTask.h.
using CallbackT = std::function<void()> |
Definition at line 46 of file RunningTask.h.
RunningTaskBase | ( | std::string const & | name | ) |
|
inline |
Constructs a running task within the class parent which calls the runningFn
in a new thread.
name | of this thread, that describes what it is doing. If string is empty, it will use the name of the class with RTTI |
Definition at line 60 of file RunningTask.h.
|
override |
Destructor stops the thread and waits for completion.
Definition at line 40 of file RunningTask.cpp.
std::string getName | ( | ) | const |
Definition at line 195 of file RunningTask.cpp.
bool isFinished | ( | ) | const |
Retrieve finished state of the thread.
The task is finished once the thread has joined.
Definition at line 151 of file RunningTask.cpp.
bool isRunning | ( | ) | const |
Retrieve running state of the thread.
The task is running when it is started until the thread method joints.
Definition at line 146 of file RunningTask.cpp.
bool isStopped | ( | ) |
Retrieve whether stop() has been called.
Has to be handled in thread function implementation for proper exit.
Definition at line 178 of file RunningTask.cpp.
void join | ( | ) |
Wait for the RunningTask to finish without telling it to finish.
Definition at line 136 of file RunningTask.cpp.
void setName | ( | const std::string & | name | ) |
void setThreadList | ( | ThreadListPtr | threadList | ) |
void start | ( | ) |
Starts the thread.
Only has effect if the task has not been started. After completion of the task, it cannot be started again.
Definition at line 60 of file RunningTask.cpp.
void stop | ( | bool | waitForJoin = true | ) |
Stops the thread.
Only has effect if the task has been started.
waitForJoin | wait for the thread to terminate and join with the process. |
Definition at line 83 of file RunningTask.cpp.
bool waitForFinished | ( | int | timeoutMS = -1 | ) |
wait blocking for thread to be finished.
The task is finished once the thread has joined.
timeoutMS | timeout in milliseconds. If -1 there is no timeout. |
Definition at line 156 of file RunningTask.cpp.
void waitForStop | ( | ) |
Wait blocking for thread until stop() has been called.
Can be used for blocking wait for stop in thread function implementation
Definition at line 184 of file RunningTask.cpp.
CallbackT callback |
Definition at line 48 of file RunningTask.h.