MADARA  3.2.3
WorkerThread.inl
Go to the documentation of this file.
1 #ifndef _MADARA_THREADS_WORKER_THREAD_INL_
2 #define _MADARA_THREADS_WORKER_THREAD_INL_
3 
11 #include "WorkerThread.h"
12 
13 namespace madara { namespace threads {
14 
15 inline void
17  double hertz,
18  utility::TimeValue & current, utility::Duration & frequency,
19  utility::TimeValue & next_epoch,
20  bool & one_shot, bool & blaster)
21 {
22  hertz_ = hertz;
23  if (hertz_ > 0.0)
24  {
26  "WorkerThread(%s)::svc:" \
27  " thread repeating at %f hz\n", name_.c_str (), hertz_);
28 
29  one_shot = false;
30 
31  frequency = utility::seconds_to_duration (1.0/hertz_);
32 
33  next_epoch = current;
34  next_epoch += frequency;
35  }
36  else if (hertz_ == 0.0)
37  {
38  // infinite hertz until terminate
39 
41  "WorkerThread(%s)::svc:" \
42  " thread blasting at infinite hz\n", name_.c_str ());
43 
44  one_shot = false;
45  blaster = true;
46  }
47  else
48  {
50  "WorkerThread(%s)::svc:" \
51  " thread running once\n", name_.c_str ());
52  }
53 }
54 
55 } }
56 
57 #endif // _MADARA_THREADS_WORKER_THREAD_H_
double hertz_
hertz rate for worker thread executions
Definition: WorkerThread.h:153
Duration seconds_to_duration(double seconds)
Returns seconds in double format as nanosecond duration.
Definition: Utility.inl:266
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
std::chrono::time_point< Clock > TimeValue
time point
Definition: Utility.h:36
Provides a quality-of-service-enabled threading library.
Definition: BaseThread.h:27
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
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.
Copyright (c) 2015 Carnegie Mellon University.
std::chrono::nanoseconds Duration
default clock duration
Definition: Utility.h:30