MADARA  3.4.1
WorkerThread.h
Go to the documentation of this file.
1 #ifndef _MADARA_THREADS_WORKER_THREAD_H_
2 #define _MADARA_THREADS_WORKER_THREAD_H_
3 
12 #include <string>
13 #include <map>
14 
16 #include "BaseThread.h"
18 #include "madara/utility/Utility.h"
19 
20 #include <thread>
21 
22 namespace madara
23 {
24 namespace threads
25 {
26 class Threader;
27 
33 {
34 public:
36  friend class Threader;
37 
42 
54  WorkerThread(const std::string& name, BaseThread* thread,
56  double hertz = -1.0)
57  : WorkerThread(name, thread, *control, *data, hertz)
58  {
59  }
60 
71  WorkerThread(const std::string& name, BaseThread* thread,
73  double hertz = -1.0);
74 
75  WorkerThread(WorkerThread&& other) = default;
79  ~WorkerThread() noexcept;
80 
85  // void operator= (const WorkerThread & input);
86 
87 protected:
88  std::thread me_;
89 
93  int svc(void);
94 
98  void run(void);
99 
110  void change_frequency(double hertz, utility::TimeValue& current,
111  utility::Duration& frequency, utility::TimeValue& next_epoch,
112  bool& one_shot, bool& blaster);
113 
115  std::string name_;
116 
118  std::unique_ptr<BaseThread> thread_ = nullptr;
119 
121  knowledge::KnowledgeBase control_;
122 
124  knowledge::KnowledgeBase data_;
125 
131 
137 
143 
149 
154 
160 
165 
170 
175 
180 
185 
190 
195 
199  double hertz_ = -1;
200 };
201 
205 typedef std::map<std::string, std::unique_ptr<WorkerThread>> NamedWorkerThreads;
206 }
207 }
208 
209 #include "WorkerThread.inl"
210 
211 #endif // _MADARA_THREADS_WORKER_THREAD_H_
madara::knowledge::KnowledgeRecord::Integer Integer
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
Abstract base class for implementing threads.
Definition: BaseThread.h:39
Starts threads with first class support of MADARA contexts.
Definition: Threader.h:36
A thread that executes BaseThread logic.
Definition: WorkerThread.h:33
knowledge::containers::Double new_hertz_
thread safe hertz reference
Definition: WorkerThread.h:153
knowledge::containers::Integer end_time_
timestamp of the last svc end
Definition: WorkerThread.h:174
knowledge::containers::Integer max_duration_
maximum duration of all runs
Definition: WorkerThread.h:189
void run(void)
Starts the thread, with entry point svc()
WorkerThread()
Default constructor.
Definition: WorkerThread.h:41
knowledge::containers::Integer start_time_
timestamp of the initial svc start
Definition: WorkerThread.h:164
knowledge::containers::Integer executions_
thread safe start flag that will be sent to the knowledge base on launch of the thread
Definition: WorkerThread.h:159
WorkerThread(const std::string &name, BaseThread *thread, knowledge::KnowledgeBase *control, knowledge::KnowledgeBase *data, double hertz=-1.0)
Constructor deprecated: use version that takes control and data by value.
Definition: WorkerThread.h:54
knowledge::containers::Integer finished_
thread safe finished flag that will be sent to the knowledge base on completion of the thread
Definition: WorkerThread.h:130
knowledge::KnowledgeBase data_
the data plane (the knowledge base)
Definition: WorkerThread.h:124
knowledge::KnowledgeBase control_
the control plane to the knowledge base
Definition: WorkerThread.h:121
knowledge::containers::Integer debug_
flag for whether or not to save debug information in control
Definition: WorkerThread.h:194
knowledge::containers::Integer started_
thread safe start flag that will be sent to the knowledge base on launch of the thread
Definition: WorkerThread.h:148
knowledge::containers::Integer last_duration_
duration of last run
Definition: WorkerThread.h:179
std::unique_ptr< BaseThread > thread_
the contained thread
Definition: WorkerThread.h:118
std::thread me_
Assignment operator.
Definition: WorkerThread.h:88
WorkerThread(WorkerThread &&other)=default
double hertz_
hertz rate for worker thread executions
Definition: WorkerThread.h:199
madara::knowledge::containers::Integer paused_
thread safe paused flag that will be sent to the knowledge base to indicate thread activities should ...
Definition: WorkerThread.h:136
~WorkerThread() noexcept
Destructor.
std::string name_
the name of the contained thread
Definition: WorkerThread.h:115
madara::knowledge::containers::Integer running_
thread safe paused flag that will be sent to the knowledge base to indicate thread activities should ...
Definition: WorkerThread.h:142
knowledge::containers::Integer min_duration_
minimum duration of all runs
Definition: WorkerThread.h:184
void change_frequency(double hertz, utility::TimeValue &current, utility::Duration &frequency, utility::TimeValue &next_epoch, bool &one_shot, bool &blaster)
Changes the frequency given a hertz rate.
knowledge::containers::Integer last_start_time_
timestamp of the last svc start
Definition: WorkerThread.h:169
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
Provides a quality-of-service-enabled threading library.
Definition: BaseThread.h:28
std::map< std::string, std::unique_ptr< WorkerThread > > NamedWorkerThreads
Collection of named threads.
Definition: WorkerThread.h:205
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:15
std::chrono::time_point< Clock > TimeValue
time point
Definition: Utility.h:36
std::chrono::nanoseconds Duration
default clock duration
Definition: Utility.h:30
Copyright(c) 2020 Galois.