Helper class to manage a long-running thread (duration of event loop)
More...
#include <EventLoopUtils.h>
|
void | waitForCond (std::unique_lock< std::mutex > &lock) |
| Helper to wait for the condition. More...
|
|
void | run () |
| Main function executed by the thread. More...
|
|
|
std::condition_variable | m_cond |
| Condition for which the thread waits most of its lifetime. More...
|
|
std::mutex | m_mutex |
| Mutex used to notify the condition. More...
|
|
bool | m_keepRunning {true} |
| The thread's inner while-loop condition variable. More...
|
|
bool | m_started {false} |
| Flag whether the main loop of the thread has started and will listen to further notifications. More...
|
|
bool | m_finished {false} |
| Flag whether the main loop of the thread has finished. More...
|
|
std::function< void()> | m_callback |
| The callback executed in each step of the thread's inner while-loop. More...
|
|
int | m_callbackIntervalMilliseconds {-1} |
| If positive, call the callback periodically with this interval regardless of the m_cond. More...
|
|
std::unique_ptr< std::thread > | m_thread |
| The thread object. More...
|
|
Helper class to manage a long-running thread (duration of event loop)
Definition at line 15 of file EventLoopUtils.h.
◆ LoopThread() [1/3]
HLT::LoopThread::LoopThread |
( |
std::function< void()> && |
callback, |
|
|
int |
callbackInterval = -1 |
|
) |
| |
|
inlineexplicit |
◆ ~LoopThread()
HLT::LoopThread::~LoopThread |
( |
| ) |
|
|
inline |
◆ LoopThread() [2/3]
◆ LoopThread() [3/3]
◆ cond()
std::condition_variable& HLT::LoopThread::cond |
( |
| ) |
|
|
inline |
◆ mutex()
std::mutex& HLT::LoopThread::mutex |
( |
| ) |
|
|
inline |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ run()
void HLT::LoopThread::run |
( |
| ) |
|
|
inlineprivate |
Main function executed by the thread.
Definition at line 44 of file EventLoopUtils.h.
46 std::unique_lock<std::mutex> lock{
m_mutex};
◆ start()
void HLT::LoopThread::start |
( |
| ) |
|
|
inline |
Keep notifying the thread until the callback is called for the first time (returns just before calling the callback)
Definition at line 79 of file EventLoopUtils.h.
81 std::this_thread::sleep_for(std::chrono::milliseconds(3));
◆ stop()
void HLT::LoopThread::stop |
( |
| ) |
|
|
inline |
◆ wait()
void HLT::LoopThread::wait |
( |
| ) |
|
|
inline |
Wait until main loop finishes.
Definition at line 93 of file EventLoopUtils.h.
98 std::this_thread::sleep_for(std::chrono::milliseconds(3));
◆ waitForCond()
void HLT::LoopThread::waitForCond |
( |
std::unique_lock< std::mutex > & |
lock | ) |
|
|
inlineprivate |
◆ m_callback
std::function<void()> HLT::LoopThread::m_callback |
|
private |
The callback executed in each step of the thread's inner while-loop.
Definition at line 28 of file EventLoopUtils.h.
◆ m_callbackIntervalMilliseconds
int HLT::LoopThread::m_callbackIntervalMilliseconds {-1} |
|
private |
If positive, call the callback periodically with this interval regardless of the m_cond.
Definition at line 30 of file EventLoopUtils.h.
◆ m_cond
std::condition_variable HLT::LoopThread::m_cond |
|
private |
Condition for which the thread waits most of its lifetime.
Definition at line 18 of file EventLoopUtils.h.
◆ m_finished
bool HLT::LoopThread::m_finished {false} |
|
private |
Flag whether the main loop of the thread has finished.
Definition at line 26 of file EventLoopUtils.h.
◆ m_keepRunning
bool HLT::LoopThread::m_keepRunning {true} |
|
private |
The thread's inner while-loop condition variable.
Definition at line 22 of file EventLoopUtils.h.
◆ m_mutex
std::mutex HLT::LoopThread::m_mutex |
|
private |
◆ m_started
bool HLT::LoopThread::m_started {false} |
|
private |
Flag whether the main loop of the thread has started and will listen to further notifications.
Definition at line 24 of file EventLoopUtils.h.
◆ m_thread
std::unique_ptr<std::thread> HLT::LoopThread::m_thread |
|
private |
The documentation for this class was generated from the following file: