SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AsyncWorker.h
Go to the documentation of this file.
1 /**
2  * \file AsyncWorker.h
3  * \brief Declaration of an async worker thread class
4  * \date May 2024
5  * \authors Marino von Wattenwyl
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #ifndef ASYNC_WORKER_H
12 #define ASYNC_WORKER_H
13 
14 #include <thread>
15 #include <atomic>
16 
17 //-----------------------------------------------------------------------------
18 //! AsyncWorker implements a async worker thread
20 {
21 public:
22  virtual ~AsyncWorker();
23 
24  void start();
25  void stop();
26  bool isReady();
27 
28 protected:
29  bool stopRequested();
30  void setReady();
31  virtual void run();
32 
33 private:
34  std::thread _thread;
35  std::atomic_bool _stop{false};
36  std::atomic_bool _ready{false};
37 };
38 //-----------------------------------------------------------------------------
39 
40 #endif
AsyncWorker implements a async worker thread.
Definition: AsyncWorker.h:20
bool isReady()
if returns true, results are valid to be retrieved
Definition: AsyncWorker.cpp:36
std::thread _thread
Definition: AsyncWorker.h:34
std::atomic_bool _ready
Definition: AsyncWorker.h:36
void setReady()
Definition: AsyncWorker.cpp:47
virtual void run()
Definition: AsyncWorker.cpp:52
std::atomic_bool _stop
Definition: AsyncWorker.h:35
void start()
Definition: AsyncWorker.cpp:20
bool stopRequested()
Definition: AsyncWorker.cpp:41
virtual ~AsyncWorker()
Definition: AsyncWorker.cpp:15