MADARA  3.2.3
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 
23 namespace madara
24 {
25  namespace threads
26  {
27  class Threader;
28 
34  {
35  public:
37  friend class Threader;
38 
43 
56  const std::string & name,
57  BaseThread * thread,
58  knowledge::KnowledgeBase * control,
60  double hertz = -1.0)
61  : WorkerThread(name, thread, *control, *data, hertz) {}
62 
73  WorkerThread (
74  const std::string & name,
75  BaseThread * thread,
78  double hertz = -1.0);
79 
81  WorkerThread &&other) = default;
85  ~WorkerThread () noexcept;
86 
91  //void operator= (const WorkerThread & input);
92 
93  protected:
94  std::thread me_;
95 
99  int svc (void);
100 
104  void run (void);
105 
116  void change_frequency (double hertz,
117  utility::TimeValue & current, utility::Duration & frequency,
118  utility::TimeValue & next_epoch,
119  bool & one_shot, bool & blaster);
120 
123 
125  std::unique_ptr<BaseThread> thread_ = nullptr;
126 
129 
132 
138 
144 
149 
153  double hertz_ = -1;
154  };
155 
159  typedef std::map <std::string, std::unique_ptr<WorkerThread>> NamedWorkerThreads;
160  }
161 }
162 
163 #include "WorkerThread.inl"
164 
165 #endif // _MADARA_THREADS_WORKER_THREAD_H_
This class stores a double within a variable context.
Definition: Double.h:32
WorkerThread()
Default constructor.
Definition: WorkerThread.h:42
knowledge::containers::Double new_hertz_
thread safe hertz reference
Definition: WorkerThread.h:148
~WorkerThread() noexcept
Destructor.
double hertz_
hertz rate for worker thread executions
Definition: WorkerThread.h:153
void run(void)
Starts the thread, with entry point svc()
std::chrono::time_point< Clock > TimeValue
time point
Definition: Utility.h:36
Provides a quality-of-service-enabled threading library.
Definition: BaseThread.h:27
std::thread me_
Assignment operator.
Definition: WorkerThread.h:94
static struct madara::knowledge::tags::string_t string
std::unique_ptr< BaseThread > thread_
the contained thread
Definition: WorkerThread.h:125
Abstract base class for implementing threads.
Definition: BaseThread.h:38
A thread that executes BaseThread logic.
Definition: WorkerThread.h:33
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:31
std::string name_
the name of the contained thread
Definition: WorkerThread.h:122
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 started_
thread safe start flag that will be sent to the knowledge base on launch of the thread ...
Definition: WorkerThread.h:143
Starts threads with first class support of MADARA contexts.
Definition: Threader.h:35
knowledge::containers::Integer finished_
thread safe finished flag that will be sent to the knowledge base on completion of the thread ...
Definition: WorkerThread.h:137
knowledge::KnowledgeBase control_
the control plane to the knowledge base
Definition: WorkerThread.h:128
int svc(void)
Task loop.
knowledge::KnowledgeBase data_
the data plane (the knowledge base)
Definition: WorkerThread.h:131
std::map< std::string, std::unique_ptr< WorkerThread > > NamedWorkerThreads
Collection of named threads.
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:55
Copyright (c) 2015 Carnegie Mellon University.
std::chrono::nanoseconds Duration
default clock duration
Definition: Utility.h:30