5 #include "ace/Time_Value.h" 13 unsigned __stdcall timed_thread_windows_glue (
void * param)
20 return (
unsigned) caller->
svc ();
38 result = this->activate ();
48 "TimedEventThread::TimedEventThread:" \
49 " thread started (result = %d)\n", result);
54 "TimedEventThread::TimedEventThread:" \
55 " failed to create thread\n");
58 std::stringstream expression;
59 expression <<
"thread.";
61 expression <<
".closed = 1";
63 #ifndef _MADARA_NO_KARL_ 67 "queued > 0 || terminated");
69 #endif // _MADARA_NO_KARL_ 81 ACE_Time_Value sleep_time;
82 ACE_Time_Value zero_time;
87 std::stringstream buffer;
88 buffer <<
"TimedEventThread[";
95 "Service thread started.\n",
96 print_prefix.c_str ());
102 "Attempting to remove an event.\n",
103 print_prefix.c_str ());
117 Event * valid = cur_event.second;
124 #ifndef _MADARA_NO_KARL_
136 "Timed Event has expired. Deleting.\n",
137 print_prefix.c_str ());
145 "Timed Event returned false. User requested a cancel. Deleting.\n",
146 print_prefix.c_str ());
154 "Timed Event added back to queue.\n",
155 print_prefix.c_str ());
157 cur_event.first += valid->
period;
164 if (sleep_time > zero_time)
168 "Not ready for timeout. Thread sleeping.\n",
169 print_prefix.c_str ());
173 wait_settings.max_wait_time = 5.0;
175 #ifndef _MADARA_NO_KARL_ 179 #endif // _MADARA_NO_KARL_ 185 #ifndef _MADARA_NO_KARL_ 188 #endif // _MADARA_NO_KARL_ This class encapsulates an entry in a KnowledgeBase.
std::pair< ACE_Time_Value, Event * > TimedEvent
TimedEventThread(TimedEventThreadInfo &info)
Constructor.
unsigned int id
thread identifier
TimedExecutor * executor
pointer to TimedExecutor caller, which provides thread-safe callbacks for shutdown information ...
KnowledgeBase * knowledge
knowledge base for executing the expression (should be same as compiled)
MADARA_Export utility::Refcounter< logger::Logger > global_logger
expression::ComponentNode * root
expression to be executed (rooted Tree)
Expression container for timed event.
Thread executing timed events.
A struct that is passed to Timed Event Thread Executors to control job handling, shutdowns, etc.
madara::knowledge::KnowledgeRecord wait(const std::string &expression, const WaitSettings &settings=WaitSettings())
Waits for an expression to be non-zero.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
CompiledExpression queued_or_terminated_
expression for checking if events are queued or terminated
CompiledExpression thread_closed_
expression for letting control plane know the thread is closed
double poll_frequency
Frequency to poll an expression for truth (in seconds)
TimedEventThreadInfo info_
info for service loop
KnowledgeBase * control_plane
For barrier and other information.
ACE_Time_Value remove(TimedEvent &cur_event)
Removes a timed event from the queue.
madara::knowledge::KnowledgeRecord evaluate(const std::string &expression, const EvalSettings &settings=EvalSettings())
Evaluates an expression.
void add(const TimedEvent &new_event)
Adds a timed event to the queue.
ACE_Time_Value period
time between executions in seconds
Encapsulates settings for a wait statement.
unsigned int executions
executions so far
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
bool is_shutdown(void)
Checks if the thread pool has been shutdown.
int svc(void)
Service loop for the thread.
int intended_executions
intended executions
~TimedEventThread()
Destructor.
bool cancel_on_false
cancel on false return value