MADARA  3.4.1
BaseThread.h
Go to the documentation of this file.
1 
2 
3 #ifndef _MADARA_THREADS_BASE_THREAD_H_
4 #define _MADARA_THREADS_BASE_THREAD_H_
5 
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include <list>
20 #include "madara/utility/StdInt.h"
21 #include "madara/MadaraExport.h"
24 
25 namespace madara
26 {
27 namespace threads
28 {
32 class WorkerThread;
33 class Threader;
34 
39 {
40 public:
44  virtual ~BaseThread() {}
45 
50  friend class WorkerThread;
51  friend class Threader;
52 
56  virtual void init(knowledge::KnowledgeBase&) {}
57 
62  virtual void run(void) = 0;
63 
71  virtual void cleanup(void) {}
72 
73 protected:
79  {
80  terminated.set_name(name + ".terminated", control);
81  paused.set_name(name + ".paused", control);
82 
83  terminated = 0;
84  paused = 0;
85  }
86 
91 
97 
102 };
103 } // namespace threads
104 } // namespace madara
105 
106 #endif // _MADARA_THREADS_BASE_THREAD_H_
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class stores an integer within a variable context.
Definition: Integer.h:32
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
Definition: Integer.inl:54
Abstract base class for implementing threads.
Definition: BaseThread.h:39
std::string name
The unique name of your thread.
Definition: BaseThread.h:90
virtual void run(void)=0
Executes the main thread logic.
virtual void cleanup(void)
Cleans up any thread residue (usually instances created in init).
Definition: BaseThread.h:71
virtual void init_control_vars(knowledge::KnowledgeBase &control)
Initializes the thread implementation's control plane variables.
Definition: BaseThread.h:78
madara::knowledge::containers::Integer terminated
thread safe terminated flag that may be set by the Threader base
Definition: BaseThread.h:96
virtual void init(knowledge::KnowledgeBase &)
Initializes thread with a MADARA context.
Definition: BaseThread.h:56
madara::knowledge::containers::Integer paused
thread safe paused flag that may be set by the Threader
Definition: BaseThread.h:101
virtual ~BaseThread()
Destructor.
Definition: BaseThread.h:44
Starts threads with first class support of MADARA contexts.
Definition: Threader.h:36
A thread that executes BaseThread logic.
Definition: WorkerThread.h:33
constexpr string_t string
Provides a quality-of-service-enabled threading library.
Definition: BaseThread.h:28
Copyright(c) 2020 Galois.