2 #include "ace/High_Res_Timer.h" 3 #include "ace/OS_NS_sys_time.h" 8 #include "madara_jni.h" 16 unsigned __stdcall worker_thread_windows_glue (
void * param)
23 return (
unsigned) caller->
svc ();
38 : thread_ (0), control_ (0), data_ (0), hertz_ (-1.0)
52 if (thread && control)
54 std::stringstream base_string;
61 base_string.str () +
".finished", *control);
63 base_string.str () +
".started", *control);
65 base_string.str () +
".hertz", *control);
99 result = this->activate ();
102 _beginthreadex(NULL, 0, worker_thread_windows_glue, (
void*)
this, 0, 0);
109 "WorkerThread::WorkerThread(%s):" \
110 " thread started (result = %d)\n",
name_.c_str (), result);
115 "WorkerThread::WorkerThread(%s):" \
116 " failed to create thread\n",
name_.c_str ());
124 "WorkerThread(%s)::svc:" \
125 " checking thread existence\n",
name_.c_str ());
139 ACE_Time_Value current = ACE_High_Res_Timer::gettimeofday ();
140 ACE_Time_Value next_epoch, frequency;
142 bool one_shot =
true;
143 bool blaster =
false;
158 "WorkerThread(%s)::svc:" \
159 " thread checking for pause\n",
name_.c_str ());
164 "WorkerThread(%s)::svc:" \
165 " thread calling run function\n",
name_.c_str ());
177 current, frequency, next_epoch, one_shot, blaster);
182 current = ACE_High_Res_Timer::gettimeofday ();
185 "WorkerThread(%s)::svc:" \
186 " thread checking for next hertz epoch\n",
name_.c_str ());
188 if (current < next_epoch)
192 "WorkerThread(%s)::svc:" \
193 " thread past epoch\n",
name_.c_str ());
195 next_epoch += frequency;
200 "WorkerThread(%s)::svc:" \
201 " thread has been terminated\n",
name_.c_str ());
206 "WorkerThread(%s)::svc:" \
207 " calling thread cleanup method\n",
name_.c_str ());
212 "WorkerThread(%s)::svc:" \
213 " deleting thread\n",
name_.c_str ());
218 "WorkerThread(%s)::svc:" \
226 "WorkerThread(%s)::svc:" \
227 " thread creation failed\n",
name_.c_str ());
WorkerThread()
Default constructor.
void operator=(const WorkerThread &input)
Assignment operator.
This class encapsulates attaching and detaching to a VM.
knowledge::KnowledgeBase * control_
the control plane to the knowledge base
virtual void init(knowledge::KnowledgeBase &)
Initializes thread with a MADARA context.
std::string get_name(void) const
Returns the name of the container.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
knowledge::KnowledgeBase * data_
the data plane (the knowledge base)
virtual void run(void)=0
Executes the main thread logic.
knowledge::containers::Double new_hertz_
thread safe hertz reference
virtual void init_control_vars(knowledge::KnowledgeBase &control)
Initializes the Java thread implementation's control plane variables.
double hertz_
hertz rate for worker thread executions
MADARA_Export utility::Refcounter< logger::Logger > global_logger
virtual void cleanup(void)
Cleans up any thread residue (usually instances created in init).
void run(void)
Runs the thread once.
MADARA_Export double sleep(double sleep_time)
Sleeps for a certain amount of time.
Optimized reference to a variable within the knowledge base.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Retrieves a knowledge value.
~WorkerThread()
Destructor.
void change_frequency(double hertz, ACE_Time_Value ¤t, ACE_Time_Value &frequency, ACE_Time_Value &next_epoch, bool &one_shot, bool &blaster)
Changes the frequency given a hertz rate.
Abstract base class for implementing threads.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
A thread that executes BaseThread logic.
This class provides a distributed knowledge base to users.
std::string name_
the name of the contained thread
knowledge::containers::Integer started_
thread safe start flag that will be sent to the knowledge base on launch of the thread ...
std::string name
The unique name of your thread.
knowledge::containers::Integer finished_
thread safe finished flag that will be sent to the knowledge base on completion of the thread ...
int svc(void)
Reads messages from a socket.
BaseThread * thread_
the contained thread
bool is_false(void) const
Checks to see if the record is false.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Atomically returns a reference to the variable.