|
ATLAS Offline Software
|
Go to the documentation of this file.
4 #ifndef TRIGSERVICES_EVENTLOOPUTILS_H
5 #define TRIGSERVICES_EVENTLOOPUTILS_H
7 #include <condition_variable>
46 std::unique_lock<std::mutex> lock{
m_mutex};
81 std::this_thread::sleep_for(std::chrono::milliseconds(3));
98 std::this_thread::sleep_for(std::chrono::milliseconds(3));
110 #endif // TRIGSERVICES_EVENTLOOPUTILS_H
std::function< void()> m_callback
The callback executed in each step of the thread's inner while-loop.
void waitForCond(std::unique_lock< std::mutex > &lock)
Helper to wait for the condition.
void wait()
Wait until main loop finishes.
LoopThread(const LoopThread &)=delete
void stop()
Flag the main loop to finish.
LoopThread & operator=(const LoopThread &)=delete
LoopThread & operator=(LoopThread &&)=delete
bool m_keepRunning
The thread's inner while-loop condition variable.
bool m_finished
Flag whether the main loop of the thread has finished.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Helper class to manage a long-running thread (duration of event loop)
LoopThread(LoopThread &&)=delete
void start()
Keep notifying the thread until the callback is called for the first time (returns just before callin...
std::mutex m_mutex
Mutex used to notify the condition.
void run()
Main function executed by the thread.
bool m_started
Flag whether the main loop of the thread has started and will listen to further notifications.
std::unique_ptr< std::thread > m_thread
The thread object.
int m_callbackIntervalMilliseconds
If positive, call the callback periodically with this interval regardless of the m_cond.
LoopThread(std::function< void()> &&callback, int callbackInterval=-1)
std::condition_variable m_cond
Condition for which the thread waits most of its lifetime.
std::condition_variable & cond()