MADARA  3.1.8
TimedExecutor.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_TIMED_EXECUTOR_H_
3 #define _MADARA_TIMED_EXECUTOR_H_
4 
5 #include <vector>
6 #include <map>
7 #include <string>
8 #include <utility>
9 #include <queue>
10 #include "madara/LockType.h"
14 
15 #include "ace/High_Res_Timer.h"
16 #include "ace/Barrier.h"
17 #include "ace/Mutex.h"
18 #include "ace/Thread_Mutex.h"
19 
28 namespace madara
29 {
30  namespace knowledge
31  {
36  struct Event
37  {
39  ACE_Time_Value delay;
40 
42  ACE_Time_Value period;
43 
44 #ifndef _MADARA_NO_KARL_
47 #endif // _MADARA_NO_KARL_
48 
54 
56  unsigned int executions;
57 
60 
63  };
64 
66  struct TimedEventThreadInfo;
67 
70 
71  typedef std::pair <ACE_Time_Value, Event *> TimedEvent;
72 
77  class MADARA_Export TimedExecutor
78  {
79  public:
83  TimedExecutor ();
84 
88  ~TimedExecutor ();
89 
94  void add (const TimedEvent & new_event);
95 
100  void add (const Event & new_event);
101 
108  ACE_Time_Value remove (TimedEvent & cur_event);
109 
113  void shutdown (void);
114 
119  bool is_shutdown (void);
120 
124  ACE_Time_Value time_until_next (void);
125 
130  void launch_threads (unsigned int threads);
131 
135  void enter_barrier (void);
136 
144  void clear_queue (void);
145 
150  knowledge::KnowledgeRecord::Integer num_threads (void);
151 
152  private:
153 
154 
156 
157 
159  typedef std::priority_queue <TimedEvent, std::vector <TimedEvent> >
161 
165  void lock (void);
166 
170  void unlock (void);
171 
175  mutable MADARA_LOCK_TYPE mutex_;
176 
181 
186 
191 
196 
201 
206 
211 
216  };
217 
223  {
229 
234 
238  unsigned int id;
239  };
240 
251  MADARA_Export Event fill_event (
253  const std::string & expression,
254  double delay = 0.0, double period = 0.0, int executions = -1);
255  }
256 }
257 
264 bool operator< (
265  const madara::knowledge::TimedEvent & lhs,
266  const madara::knowledge::TimedEvent & rhs);
267 
268 
269 
270 #endif // _MADARA_TIMED_EXECUTOR_H_
MADARA_Export Event fill_event(KnowledgeBase &knowledge, const std::string &expression, double delay=0.0, double period=0.0, int executions=-1)
Fills an event struct.
This class executes expression events at specified times.
Definition: TimedExecutor.h:77
std::priority_queue< TimedEvent, std::vector< TimedEvent > > PriorityQueue
guard for access and changes
VariableReference queue_size_
Reference to queue size in the control plane.
MADARA_LOCK_TYPE mutex_
Mutex for local changes.
std::pair< ACE_Time_Value, Event * > TimedEvent
Definition: TimedExecutor.h:69
unsigned int id
thread identifier
TimedExecutor * executor
pointer to TimedExecutor caller, which provides thread-safe callbacks for shutdown information ...
bool operator<(const madara::knowledge::TimedEvent &lhs, const madara::knowledge::TimedEvent &rhs)
Comparison for higher event priorities.
KnowledgeBase * knowledge
knowledge base for executing the expression (should be same as compiled)
Definition: TimedExecutor.h:53
TimedEventThread ** threads_
Timed Event Threads.
expression::ComponentNode * root
expression to be executed (rooted Tree)
Definition: TimedExecutor.h:46
knowledge::KnowledgeRecord::Integer num_threads_
Number of thread.
Optimized reference to a variable within the knowledge base.
Provides a quality-of-service-enabled threading library.
Definition: BaseThread.h:27
Expression container for timed event.
Definition: TimedExecutor.h:36
Thread executing timed events.
A struct that is passed to Timed Event Thread Executors to control job handling, shutdowns, etc.
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:44
ACE_Time_Value delay
delay before first execution
Definition: TimedExecutor.h:39
An abstract base class defines a simple abstract implementation of an expression tree node...
Definition: ComponentNode.h:35
PriorityQueue events_
Event queue.
VariableReference terminated_
Reference to terminated condition within control plane.
static constexpr struct madara::knowledge::tags::string_t string
TimedEventThreadInfo * thread_info_
Vector of thread info.
VariableReference threads_ref_
Reference to the number of threads in the control plane.
KnowledgeBase * control_plane
For barrier and other information.
Provides functions and classes for the distributed knowledge base.
KnowledgeBase control_plane_
For barrier and other information.
Copyright (c) 2015 Carnegie Mellon University.
ACE_Time_Value period
time between executions in seconds
Definition: TimedExecutor.h:42
unsigned int executions
executions so far
Definition: TimedExecutor.h:56
int intended_executions
intended executions
Definition: TimedExecutor.h:59
bool cancel_on_false
cancel on false return value
Definition: TimedExecutor.h:62