35#ifndef _UTILS_TIMEBASE_HXX_
36#define _UTILS_TIMEBASE_HXX_
82 return ((t1 - t2) * 4) / rate;
93 elapsed = ((elapsed * std::abs(
rate_)) + 2) / 4;
111 return ::gmtime_r(&now, result);
125 *month = tm.tm_mon + 1;
164 return tm.tm_year + 1900;
198 int16_t rate, time_t fast_sec,
long long *real_nsec)
200 if (rate != 0 && rate >= -2048 && rate <= 2047)
203 ((
SEC_TO_NSEC(std::abs(fast_sec)) * 4) + (std::abs(rate) / 2)) /
207 *real_nsec = -(*real_nsec);
224 int16_t rate,
long long real_nsec, time_t *fast_sec)
226 if (rate != 0 && rate >= -2048 && rate <= 2047)
228 *fast_sec = (std::abs(
NSEC_TO_SEC(real_nsec * rate)) + 2) / 4;
229 if ((real_nsec < 0 && rate > 0) || (real_nsec >= 0 && rate < 0))
231 *fast_sec = -(*fast_sec);
255 *real_nsec -= monotonic;
277 *real_nsec = std::abs(*real_nsec);
See OSMutexLock in os/OS.hxx.
Lightweight locking class for protecting small critical sections.
static long long get_monotonic()
Get the monotonic time since the system started.
Helper class for implementing fast clocks.
int day_of_week()
Get the day of the week.
bool real_nsec_to_fast_sec_period(int16_t rate, long long real_nsec, time_t *fast_sec)
Convert period in real nsec to a fast clock period.
bool fast_sec_to_real_nsec_period_abs(time_t fast_sec, long long *real_nsec)
Convert fast clock absolute (negative or positive) period to a positive (absolute) period in real nse...
struct tm * gmtime_r(struct tm *result)
Get the time as a standard struct tm.
uint16_t started_
true if clock is started
time_t seconds_
Clock time at the last time update.
int day_of_year()
Get the day of the year.
int date(int *month, int *day)
Get the date (month/day).
bool is_started()
Test of the clock is started (rate could still be 0).
std::pair< time_t, int16_t > time_and_rate_quarters()
Get the time as a value of seconds relative to the system epoch.
int16_t get_rate_quarters()
Report the clock rate as a 12-bit fixed point number (-512.00 to 511.75).
bool is_running()
Test of the clock is running.
long long timestamp_
OS time at the last time update.
bool real_nsec_until_fast_time_abs(time_t fast_sec, long long *real_nsec)
Convert a fast time to absolute nsec until it will occur.
time_t compare_realtime(time_t t1, time_t t2)
Get the difference in time scaled to real time.
time_t time()
Get the time as a value of seconds relative to the system epoch.
void sync(const TimeBase &other)
Synchronizes this time with a different clock.
bool fast_sec_to_real_nsec_period(int16_t rate, time_t fast_sec, long long *real_nsec)
Convert fast clock period to a period in real nsec.
int16_t rate_
effective clock rate
#define NSEC_TO_SEC_ROUNDED(_nsec)
Convert a nanosecond value to a second value.
#define SEC_TO_NSEC(_sec)
Convert a second value to a nanosecond value.
#define NSEC_TO_SEC(_nsec)
Convert a nanosecond value to a second value.