GRUTinizer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StoppableThread.h
Go to the documentation of this file.
1 #ifndef _STOPPABLETHREAD_H_
2 #define _STOPPABLETHREAD_H_
3 
4 #ifndef __CINT__
5 #include <atomic>
6 #include <condition_variable>
7 #include <thread>
8 #endif
9 
10 #include <string>
11 
12 #include "TObject.h"
13 
15 public:
17  virtual ~StoppableThread();
18 
19  void Resume();
20  void Pause();
21  void Stop();
22  bool IsPaused();
23  bool IsRunning();
24  void Join();
25 
26  virtual std::string Status() { return ""; }
27 
28 protected:
29  virtual bool Iteration() = 0;
30 
31 private:
32  StoppableThread(const StoppableThread& other) { }
34 
35  void Loop();
36 
37 #ifndef __CINT__
38  std::thread thread;
39  std::atomic_bool running;
40  std::atomic_bool force_stop;
41  std::atomic_bool paused;
42  std::condition_variable paused_wait;
43  std::mutex pause_mutex;
44 #endif
45 
47 };
48 
49 
50 #endif /* _STOPPABLETHREAD_H_ */