Defines for getting and processing the current system type programmatically.
More...
#include <time.h>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <limits>
#include <thread>
#include "my_config.h"
#include "my_time_t.h"
Go to the source code of this file.
|
using | UTC_clock = std::chrono::system_clock |
|
using | Timeout_type = std::uint64_t |
| Type alias to reduce chance of conversion errors on timeout values. More...
|
|
Defines for getting and processing the current system type programmatically.
◆ Timeout_type
Type alias to reduce chance of conversion errors on timeout values.
◆ UTC_clock
◆ cmp_timespec()
int cmp_timespec |
( |
struct timespec * |
ts1, |
|
|
struct timespec * |
ts2 |
|
) |
| |
|
inline |
Compare two timespec structs.
- Return values
-
1 | If ts1 ends after ts2. |
-1 | If ts1 ends before ts2. |
0 | If ts1 is equal to ts2. |
◆ diff_timespec()
unsigned long long int diff_timespec |
( |
struct timespec * |
ts1, |
|
|
struct timespec * |
ts2 |
|
) |
| |
|
inline |
Calculate the diff between two timespec values.
- Returns
- difference in nanoseconds between ts1 and ts2
◆ get_date()
void get_date |
( |
char * |
to, |
|
|
int |
flag, |
|
|
time_t |
date |
|
) |
| |
Store textual representation of date in a character array.
- Parameters
-
[out] | to | character array where date will be written |
| flag | format of date: If flag & GETDATE_TIME Return date and time If flag & GETDATE_SHORT_DATE Return short date format YYMMDD If flag & GETDATE_HHMMSSTIME Return time in HHMMDD format. If flag & GETDATE_GMT Date/time in GMT If flag & GETDATE_FIXEDLENGTH Return fixed length date/time |
| date | time_t value for conversion. |
- Note
- If flag & GETDATE_T_DELIMITER Append 'T' between date and time. If flag & GETDATE_SHORT_DATE_FULL_YEAR Return compact date format YYYYMMDD
◆ my_getsystime()
unsigned long long int my_getsystime |
( |
| ) |
|
|
inline |
Get high-resolution time.
Forwards to std::chrono.
- Returns
- current high-resolution time in multiples of 100 nanoseconds.
◆ my_micro_time()
unsigned long long int my_micro_time |
( |
| ) |
|
|
inline |
Return time in microseconds.
Uses std::chrono::high_resolution_clock
- Return values
-
Number | of microseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC) |
◆ my_micro_time_to_timeval() [1/2]
void my_micro_time_to_timeval |
( |
std::uint64_t |
micro_time, |
|
|
my_timeval * |
tm |
|
) |
| |
|
inline |
Convert microseconds since epoch to my_timeval.
- Parameters
-
| micro_time | Microseconds. |
[out] | tm | A timeval variable to write to. |
◆ my_micro_time_to_timeval() [2/2]
void my_micro_time_to_timeval |
( |
std::uint64_t |
micro_time, |
|
|
timeval * |
tm |
|
) |
| |
|
inline |
Convert microseconds since epoch to timeval.
Prefer
my_micro_time_to_timeval(std::uint64_t micro_time, my_timeval *tm)
which is 64 bits safe on all platforms: Window's timeval's long members are only 32 bits. Unless you need to use the host system's struct timeval, of course.
- Parameters
-
| micro_time | Microseconds. |
[out] | tm | A timeval variable to write to. |
◆ my_milli_time()
unsigned long long int my_milli_time |
( |
| ) |
|
|
inline |
Return time in milliseconds.
Uses std::chrono::high_resolution_clock
- Return values
-
Number | of milliseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC) |
◆ my_sleep()
void my_sleep |
( |
time_t |
m_seconds | ) |
|
|
inline |
Wait a given number of microseconds.
- Parameters
-
m_seconds | number of microseconds to wait. |
◆ my_time()
Return current time.
Takes an int argument for backward compatibility. This argument is ignored.
- Deprecated:
- New code should use std::time() directly.
- Return values
-
◆ set_timespec()
void set_timespec |
( |
struct timespec * |
abstime, |
|
|
Timeout_type |
sec |
|
) |
| |
Set the value of a timespec object to the current time plus a number of seconds using seconds.
- Note
- the sec value is capped at std::chrono::seconds::max()
- Parameters
-
[out] | abstime | time value being modified |
| sec | number of seconds to add to current time |
◆ set_timespec_nsec()
void set_timespec_nsec |
( |
struct timespec * |
abstime, |
|
|
Timeout_type |
nsec |
|
) |
| |
Set the value of a timespec object to the current time plus a number of nanosconds.
- Note
- the sec value is capped at std::chrono::nanoseconds::max()
- Parameters
-
[out] | abstime | time value being modified |
| nsec | number of nanoseconds to add to current time |
◆ timespec_now()
timespec timespec_now |
( |
| ) |
|
◆ GETDATE_DATE_TIME
constexpr const int GETDATE_DATE_TIME = 1 |
|
constexpr |
◆ GETDATE_FIXEDLENGTH
constexpr const int GETDATE_FIXEDLENGTH = 16 |
|
constexpr |
◆ GETDATE_GMT
constexpr const int GETDATE_GMT = 8 |
|
constexpr |
◆ GETDATE_HHMMSSTIME
constexpr const int GETDATE_HHMMSSTIME = 4 |
|
constexpr |
◆ GETDATE_SHORT_DATE
constexpr const int GETDATE_SHORT_DATE = 2 |
|
constexpr |
◆ GETDATE_SHORT_DATE_FULL_YEAR
constexpr const int GETDATE_SHORT_DATE_FULL_YEAR = 64 |
|
constexpr |
◆ GETDATE_T_DELIMITER
constexpr const int GETDATE_T_DELIMITER = 32 |
|
constexpr |
◆ TIMEOUT_INF
Initial value:=
std::numeric_limits<Timeout_type>::max() - 1
Value representing "infinite" timeout.
◆ TIMESPEC_POSINF
constexpr const timespec TIMESPEC_POSINF |
|
constexpr |
Initial value:= {
std::numeric_limits<decltype(timespec::tv_sec)>::max(), 999999999}
The maximum timespec value used to represent "inifinity" (as when requesting an "infinite" timeout.