7 #include "madara_jni.h" 23 : name_ (name), thread_ (thread), control_ (control), data_ (data),
28 std::stringstream base_string;
35 base_string.str () +
".finished", control);
37 base_string.str () +
".started", control);
39 base_string.str () +
".hertz", control);
52 "WorkerThread::~WorkerThread(%s):" \
53 " thread wasn't joined before destruction\n",
name_.c_str());
57 catch (
const std::system_error &e) {
59 "WorkerThread::~WorkerThread(%s):" \
60 " error trying to detach: %s\n",
name_.c_str(), e.what());
93 std::ostringstream os;
94 os << std::this_thread::get_id() <<
" spawned " <<
me_.get_id() << std::endl;
97 "WorkerThread::WorkerThread(%s):" \
98 " thread started %s\n",
name_.c_str (), os.str().c_str());
100 catch (
const std::exception &e)
103 "WorkerThread::WorkerThread(%s):" \
104 " failed to create thread: %s\n",
name_.c_str (), e.what ());
113 "WorkerThread(%s)::svc:" \
114 " checking thread existence\n",
name_.c_str ());
132 bool one_shot =
true;
133 bool blaster =
false;
148 "WorkerThread(%s)::svc:" \
149 " thread checking for pause\n",
name_.c_str ());
154 "WorkerThread(%s)::svc:" \
155 " thread calling run function\n",
name_.c_str ());
159 }
catch (
const std::exception &e) {
161 "WorkerThread(%s)::svc:" \
162 " exception thrown: %s\n",
name_.c_str (), e.what());
173 current, frequency, next_epoch, one_shot, blaster);
181 "WorkerThread(%s)::svc:" \
182 " thread checking for next hertz epoch\n",
name_.c_str ());
184 if (current < next_epoch)
188 "WorkerThread(%s)::svc:" \
189 " thread past epoch\n",
name_.c_str ());
191 next_epoch += frequency;
196 "WorkerThread(%s)::svc:" \
197 " thread has been terminated\n",
name_.c_str ());
202 "WorkerThread(%s)::svc:" \
203 " calling thread cleanup method\n",
name_.c_str ());
208 "WorkerThread(%s)::svc:" \
209 " deleting thread\n",
name_.c_str ());
212 "WorkerThread(%s)::svc:" \
220 "WorkerThread(%s)::svc:" \
221 " thread creation failed\n",
name_.c_str ());
WorkerThread()
Default constructor.
This class encapsulates attaching and detaching to a VM.
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::containers::Double new_hertz_
thread safe hertz reference
~WorkerThread() noexcept
Destructor.
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
void run(void)
Starts the thread, with entry point svc()
std::chrono::time_point< Clock > TimeValue
time point
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.
Provides a quality-of-service-enabled threading library.
double sleep(double sleep_time)
Sleeps for a certain amount of time.
TimeValue get_time_value(void)
Returns a time of day as a chrono time value If simtime feature is enabled, this may be simulation ti...
std::thread me_
Assignment operator.
std::unique_ptr< BaseThread > thread_
the contained thread
Abstract base class for implementing threads.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
This class provides a distributed knowledge base to users.
std::string name_
the name of the contained thread
void change_frequency(double hertz, utility::TimeValue ¤t, 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 ...
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 ...
knowledge::KnowledgeBase control_
the control plane to the knowledge base
knowledge::KnowledgeBase data_
the data plane (the knowledge base)
Copyright (c) 2015 Carnegie Mellon University.
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.
std::chrono::nanoseconds Duration
default clock duration