+}
+
+long long int system_time_s()
+{
+ struct timespec t_sec;
+ long long int timestamp_sec;
+
+ if(!::clock_gettime(CLOCK_MONOTONIC, &t_sec))
+ timestamp_sec = t_sec.tv_sec;
+ return timestamp_sec;
+}
+
+frequency_clock_t::frequency_clock_t()
+ : frequency_{10.0}, last_tick_{0}, time_function_{nullptr}
+{}
+
+
+frequency_clock_t::frequency_clock_t(float frequency)
+ : frequency_{frequency}, last_tick_{0}, time_function_{nullptr}
+{}
+
+/// @brief Return the period in ms given the frequency in hertz.
+float frequency_clock_t::frequency_to_period(float frequency)
+{
+ return 1 / frequency * MS_PER_SECOND;
+}
+
+bool frequency_clock_t::started()
+{
+ return last_tick_ != 0;
+}
+
+time_function_t frequency_clock_t::get_time_function()
+{
+ return time_function_ != nullptr ? time_function_ : system_time_ms;
+}
+
+bool frequency_clock_t::elapsed(bool stagger)
+{
+ float period = frequency_to_period(frequency_);
+ float elapsed_time = 0;
+ if(!started() && stagger)
+ last_tick_ = get_time_function()() - (rand() % int(period));
+ else
+ // Make sure it ticks the the first call
+ elapsed_time = !started() ? period : get_time_function()() - last_tick_;
+
+ return frequency_ == 0 || elapsed_time >= period;
+}
+
+float frequency_clock_t::get_frequency() const
+{
+ return frequency_;
+}
+
+/// @brief Force the clock to tick, regardless of it its time has actually
+/// elapsed.
+void frequency_clock_t::tick()
+{
+ last_tick_ = get_time_function()();