#include <mostlyharmless_TaskThread.h>
|
| std::function< void(void)> | action { nullptr } |
◆ ~TaskThread()
| mostly_harmless::utils::TaskThread::~TaskThread |
( |
| ) |
|
|
noexcept |
Destructor. Calls stop, which joins the internal thread, so will block if the thread is running!
◆ hasSignalledStop()
| auto mostly_harmless::utils::TaskThread::hasSignalledStop |
( |
| ) |
const -> bool |
|
nodiscardnoexcept |
Retrieves the state of the atomic bool described in signalStop() - use this in your custom thread action to respond to cancellation requests if needed (again, does nothing on it's own!)
- Returns
- The state of the should_stop bool.
◆ isThreadRunning()
| auto mostly_harmless::utils::TaskThread::isThreadRunning |
( |
| ) |
const -> bool |
|
nodiscardnoexcept |
Gives a loose indication of whether the thread is still running or not - loose, because this will only get set after the user action has been run, not within. This means there may be a few cpu cycles discrepancy between when you think this should return true and when it actually returns true. TLDR, don't rely on it for anything timing critical!
- Returns
- Whether the thread is running or not.
◆ perform()
| auto mostly_harmless::utils::TaskThread::perform |
( |
| ) |
-> void |
Performs the action lambda (if it's been set) on a std::thread, and sets isThreadRunning to false on scope exit.
◆ signalStop()
| auto mostly_harmless::utils::TaskThread::signalStop |
( |
| ) |
-> void |
Sets an internal atomic bool that the thread should exit. Like sleep() and wake(), doesn't actually do anything on its own, pair this with usage of hasSignalledStop() in your custom thread action.
◆ sleep()
| auto mostly_harmless::utils::TaskThread::sleep |
( |
| ) |
-> void |
For use in your action lambda, pauses the thread's execution until it's woken via wake(). Internally just uses a std::condition_variable and an atomic "canWakeUp" bool - this call is equivalent to std::condition_variable::wait(). Note that this doesn't actually do anything on its own unless you call sleep in your action - it's just there if you need it!
◆ stop()
| auto mostly_harmless::utils::TaskThread::stop |
( |
| ) |
-> void |
|
noexcept |
Calls signalStop(), joins the thread, and resets the internal state for reuse.
◆ wake()
| auto mostly_harmless::utils::TaskThread::wake |
( |
| ) |
-> void |
Paired with sleep, sets the canWakeUp bool to true, and notifies the underlying condition variable. All ramblings from wake()` also apply here.
◆ action
| std::function<void(void)> mostly_harmless::utils::TaskThread::action { nullptr } |
A user-settable lambda to be invoked on the internal std::thread. Put your threaded logic here!!
◆ canWakeUp
| std::atomic<bool> mostly_harmless::utils::TaskThread::canWakeUp { false } |
◆ conditionVariable
| std::condition_variable mostly_harmless::utils::TaskThread::conditionVariable |
◆ mutex
| std::mutex mostly_harmless::utils::TaskThread::mutex |
The documentation for this class was generated from the following file: