13 #if defined(ECL_IS_POSIX)
20 #include "../../include/ecl/time/snooze_pos.hpp"
36 Snooze::Snooze(
const Duration &time,
const bool& validate) { period(time, validate); }
38 void Snooze::period(
const Duration &time,
const bool& validate) {
39 validate_times = validate;
40 time_period.tv_sec = time.sec();
41 time_period.tv_nsec = time.nsec();
42 wrap_value_ns = 1000000000L-time_period.tv_nsec;
46 void Snooze::initialise() {
47 epoch_time(time_value);
50 void Snooze::operator()() {
54 sleep_until(time_value);
57 void Snooze::add_period() {
60 if ( time_value.tv_nsec > wrap_value_ns ) {
61 time_value.tv_nsec = time_value.tv_nsec - wrap_value_ns;
62 time_value.tv_sec += 1;
64 time_value.tv_nsec += time_period.tv_nsec;
67 time_value.tv_sec += time_period.tv_sec;
69 if ( validate_times ) {
74 void Snooze::validate() {
76 TimeStructure time_current;
77 epoch_time(time_current);
79 if ( time_current.tv_sec > time_value.tv_sec ) {
81 time_value.tv_sec = time_current.tv_sec;
82 time_value.tv_nsec = time_current.tv_nsec;
84 }
else if ( time_current.tv_sec == time_value.tv_sec ) {
85 if ( time_current.tv_nsec > time_value.tv_nsec ) {
87 time_value.tv_sec = time_current.tv_sec;
88 time_value.tv_nsec = time_current.tv_nsec;