Reliable high precision monotonous clock source. More...

#include <senf/Scheduler/ClockService.hh>

Inheritance diagram for senf::ClockService:

Public Types

typedef config::time_type clock_type
 ClockService timer data type. More...
 
typedef std::int64_t int64_type
 Supplementary integer type. More...
 
typedef boost::posix_time::ptime abstime_type
 Absolute time data type. More...
 
typedef boost::posix_time::time_duration reltime_type
 Relative time data type. More...
 

Static Public Member Functions

static clock_type now ()
 Return current clock value. More...
 
static abstime_type abstime (clock_type const &clock)
 Convert clock to absolute time. More...
 
static reltime_type reltime (clock_type const &clock)
 Convert clock to relative time. More...
 
static clock_type clock (abstime_type const &time)
 Convert absolute time to clock value. More...
 
static clock_type from_time_t (time_t const &time)
 Convert legacy time_t to clock value. More...
 
static time_t to_time_t (clock_type const &time)
 Convert legacy time_t to clock value to legacy time_t. More...
 
static clock_type from_timeval (timeval const &time)
 Convert legacy timeval to clock value. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR clock_type nanoseconds (int64_type const &v)
 Convert v nanoseconds to clock_type. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR clock_type microseconds (int64_type const &v)
 Convert v microseconds to clock_type. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR clock_type milliseconds (int64_type const &v)
 Convert v milliseconds to clock_type. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR clock_type seconds (int64_type const &v)
 Convert v seconds to clock_type. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR clock_type minutes (int64_type const &v)
 Convert v minutes to clock_type. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR clock_type hours (int64_type const &v)
 Convert v hours to clock_type. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR clock_type days (int64_type const &v)
 Convert v days to clock_type. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_nanoseconds (clock_type const &v)
 Convert v to nanoseconds. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_microseconds (clock_type const &v)
 Convert v to microseconds. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_milliseconds (clock_type const &v)
 Convert v to milliseconds. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_seconds (clock_type const &v)
 Convert v to seconds. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_minutes (clock_type const &v)
 Convert v to minutes. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_hours (clock_type const &v)
 Convert v to hours. More...
 
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_days (clock_type const &v)
 Convert v to days. More...
 
static void restart ()
 Force re-synchronization of abstime and clock. More...
 

Static Public Attributes

static constexpr clock_type maxTime = std::numeric_limits<config::time_type>::max()
 

Detailed Description

Reliable high precision monotonous clock source.

The ClockService provides a highly accurate monotonous clock source based on gettimeofday(). However, it takes additional precautions to detect clock skew.

Implementation note:
The funny mixture of static and non-static members stems from the old implementation based on interval timers and gettimeofday(). The current implementation uses POSIX clocks and is much simpler and more precise.

Definition at line 62 of file ClockService.hh.

Member Typedef Documentation

◆ abstime_type

typedef boost::posix_time::ptime senf::ClockService::abstime_type

Absolute time data type.

Boost.DateTime datatype used to represent absolute date/time values.

Definition at line 91 of file ClockService.hh.

◆ clock_type

ClockService timer data type.

Unsigned integer type representing scheduler time. Scheduler time is measured in nanoseconds relative to some implementation defined reference time.

Definition at line 78 of file ClockService.hh.

◆ int64_type

typedef std::int64_t senf::ClockService::int64_type

Supplementary integer type.

This type is used to represent varies supplementary values (e.g. number of microseconds)

Definition at line 84 of file ClockService.hh.

◆ reltime_type

typedef boost::posix_time::time_duration senf::ClockService::reltime_type

Relative time data type.

Boost.DateTime datatype used to represent time intervals

Definition at line 98 of file ClockService.hh.

Member Function Documentation

◆ abstime()

static abstime_type senf::ClockService::abstime ( clock_type const &  clock)
static

Convert clock to absolute time.

This member converts a clock value into an absolute Boost.DateTime value.

Note
You should not base timeout calculations on this absolute time value. Clock time is guaranteed to be monotonous, absolute time may be non-monotonous if the system date/time is changed.

◆ clock()

static clock_type senf::ClockService::clock ( abstime_type const &  time)
static

Convert absolute time to clock value.

This member convert an absolute time value into the corresponding clock value.

See also
abstime

◆ days()

static SENF_CLOCKSERVICE_CONSTEXPR clock_type senf::ClockService::days ( int64_type const &  v)
static

Convert v days to clock_type.

◆ from_time_t()

static clock_type senf::ClockService::from_time_t ( time_t const &  time)
static

Convert legacy time_t to clock value.

This member converts an absolute time value represented as a time_t value into a clock value

◆ from_timeval()

static clock_type senf::ClockService::from_timeval ( timeval const &  time)
static

Convert legacy timeval to clock value.

This member converts an absolute time value represented as a timeval value into a clock value

◆ hours()

static SENF_CLOCKSERVICE_CONSTEXPR clock_type senf::ClockService::hours ( int64_type const &  v)
static

Convert v hours to clock_type.

◆ in_days()

static SENF_CLOCKSERVICE_CONSTEXPR int64_type senf::ClockService::in_days ( clock_type const &  v)
static

Convert v to days.

◆ in_hours()

static SENF_CLOCKSERVICE_CONSTEXPR int64_type senf::ClockService::in_hours ( clock_type const &  v)
static

Convert v to hours.

◆ in_microseconds()

static SENF_CLOCKSERVICE_CONSTEXPR int64_type senf::ClockService::in_microseconds ( clock_type const &  v)
static

Convert v to microseconds.

◆ in_milliseconds()

static SENF_CLOCKSERVICE_CONSTEXPR int64_type senf::ClockService::in_milliseconds ( clock_type const &  v)
static

Convert v to milliseconds.

◆ in_minutes()

static SENF_CLOCKSERVICE_CONSTEXPR int64_type senf::ClockService::in_minutes ( clock_type const &  v)
static

Convert v to minutes.

◆ in_nanoseconds()

static SENF_CLOCKSERVICE_CONSTEXPR int64_type senf::ClockService::in_nanoseconds ( clock_type const &  v)
static

Convert v to nanoseconds.

◆ in_seconds()

static SENF_CLOCKSERVICE_CONSTEXPR int64_type senf::ClockService::in_seconds ( clock_type const &  v)
static

Convert v to seconds.

◆ microseconds()

static SENF_CLOCKSERVICE_CONSTEXPR clock_type senf::ClockService::microseconds ( int64_type const &  v)
static

Convert v microseconds to clock_type.

◆ milliseconds()

static SENF_CLOCKSERVICE_CONSTEXPR clock_type senf::ClockService::milliseconds ( int64_type const &  v)
static

Convert v milliseconds to clock_type.

◆ minutes()

static SENF_CLOCKSERVICE_CONSTEXPR clock_type senf::ClockService::minutes ( int64_type const &  v)
static

Convert v minutes to clock_type.

◆ nanoseconds()

static SENF_CLOCKSERVICE_CONSTEXPR clock_type senf::ClockService::nanoseconds ( int64_type const &  v)
static

Convert v nanoseconds to clock_type.

◆ now()

static clock_type senf::ClockService::now ( )
static

Return current clock value.

◆ reltime()

static reltime_type senf::ClockService::reltime ( clock_type const &  clock)
static

Convert clock to relative time.

This member converts a clock value into a relative Boost.DateTime time interval

Note
The resolution of reltime_type might be smaller than the clock_type resolution

◆ restart()

static void senf::ClockService::restart ( )
static

Force re-synchronization of abstime and clock.

Calling the member should never be necessary since abstime() / clock() automatically call restart() if needed

◆ seconds()

static SENF_CLOCKSERVICE_CONSTEXPR clock_type senf::ClockService::seconds ( int64_type const &  v)
static

Convert v seconds to clock_type.

◆ to_time_t()

static time_t senf::ClockService::to_time_t ( clock_type const &  time)
static

Convert legacy time_t to clock value to legacy time_t.

This member converts a clock value into an absolute time value represented as a time_t in UTC !

Member Data Documentation

◆ maxTime

constexpr clock_type senf::ClockService::maxTime = std::numeric_limits<config::time_type>::max()
static

Definition at line 102 of file ClockService.hh.


The documentation for this class was generated from the following files: