Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_core/time.h
10
//! @brief Time definitions.
11
12
#ifndef ROC_CORE_TIME_H_
13
#define ROC_CORE_TIME_H_
14
15
#include "
roc_core/stddefs.h
"
16
17
namespace
roc
{
18
namespace
core
{
19
20
//! Clock identifier.
21
enum
clock_t
{
22
//! Virtual monotonic clock.
23
//!
24
//! @remarks
25
//! Starts at unspecified point of time.
26
//!
27
//! When platform supports it, uses the clock source that grows monotonically. It
28
//! never jumps backwards and is not affected by system clock change.
29
//!
30
//! This clock is still subject to clock *rate* adjustments applied by NTP daemon.
31
//! When it performs synchronization, it may slightly speed up or slow down both
32
//! unix and monotonic clocks for a while.
33
//!
34
//! Usually this clock is reset after reboot.
35
//! Usually this clock does not count time spent in suspended state.
36
//!
37
//! @note
38
//! If platform does not have monotonic clock source, unix clock is used.
39
//! Actual precision is platform-dependent.
40
ClockMonotonic
,
41
42
//! Real-time Unix-time UTC clock.
43
//!
44
//! @remarks
45
//! Starts at 1 Jan 1970 00:00:00 UTC.
46
//!
47
//! May instantly jump forwards or backwards when system administrator sets time.
48
//! May speed up or slow down when NTP daemon adjusts clock rate.
49
//! May experience discontinuities when NTP daemon inserts leap seconds.
50
//!
51
//! @note
52
//! Available on all platforms.
53
//! Actual precision is platform-dependent.
54
ClockUnix
55
};
56
57
//! Nanoseconds.
58
typedef
int64_t
nanoseconds_t
;
59
60
//! One nanosecond represented in nanoseconds.
61
const
nanoseconds_t
Nanosecond
= 1;
62
63
//! One microsecond represented in nanoseconds.
64
const
nanoseconds_t
Microsecond
= 1000 *
Nanosecond
;
65
66
//! One millisecond represented in nanoseconds.
67
const
nanoseconds_t
Millisecond
= 1000 *
Microsecond
;
68
69
//! One second represented in nanoseconds.
70
const
nanoseconds_t
Second
= 1000 *
Millisecond
;
71
72
//! One minute represented in nanoseconds.
73
const
nanoseconds_t
Minute
= 60 *
Second
;
74
75
//! One hour represented in nanoseconds.
76
const
nanoseconds_t
Hour
= 60 *
Minute
;
77
78
//! One day represented in nanoseconds.
79
const
nanoseconds_t
Day
= 24 *
Hour
;
80
81
//! Get current timestamp in nanoseconds.
82
nanoseconds_t
timestamp
(
clock_t
clock);
83
84
//! Sleep until the specified absolute time point has been reached.
85
//! @remarks
86
//! @p timestamp specifies absolute time point in nanoseconds.
87
void
sleep_until
(
clock_t
clock,
nanoseconds_t
timestamp
);
88
89
//! Sleep specified amount of time.
90
//! @remarks
91
//! @p duration specifies number of nanoseconds to sleep.
92
void
sleep_for
(
clock_t
clock,
nanoseconds_t
duration);
93
94
//! Convert timestamp in nanoseconds format to broken-down time.
95
//! @note
96
//! std::tm has precision of one second.
97
std::tm
nanoseconds_2_tm
(
nanoseconds_t
timestamp
);
98
99
//! Convert timestamp from broken-down time to nanoseconds format.
100
//! @note
101
//! std::tm has precision of one second.
102
nanoseconds_t
tm_2_nanoseconds
(std::tm tm);
103
104
//! Compares a and b if they close enough.
105
bool
ns_equal_delta
(
nanoseconds_t
a,
nanoseconds_t
b,
nanoseconds_t
delta);
106
107
}
// namespace core
108
}
// namespace roc
109
110
#endif
// ROC_CORE_TIME_H_
roc::core
General-purpose building blocks and platform abstraction layer.
roc::core::Millisecond
const nanoseconds_t Millisecond
One millisecond represented in nanoseconds.
Definition
time.h:67
roc::core::Nanosecond
const nanoseconds_t Nanosecond
One nanosecond represented in nanoseconds.
Definition
time.h:61
roc::core::ns_equal_delta
bool ns_equal_delta(nanoseconds_t a, nanoseconds_t b, nanoseconds_t delta)
Compares a and b if they close enough.
roc::core::Day
const nanoseconds_t Day
One day represented in nanoseconds.
Definition
time.h:79
roc::core::timestamp
nanoseconds_t timestamp(clock_t clock)
Get current timestamp in nanoseconds.
roc::core::nanoseconds_2_tm
std::tm nanoseconds_2_tm(nanoseconds_t timestamp)
Convert timestamp in nanoseconds format to broken-down time.
roc::core::Second
const nanoseconds_t Second
One second represented in nanoseconds.
Definition
time.h:70
roc::core::Minute
const nanoseconds_t Minute
One minute represented in nanoseconds.
Definition
time.h:73
roc::core::Microsecond
const nanoseconds_t Microsecond
One microsecond represented in nanoseconds.
Definition
time.h:64
roc::core::clock_t
clock_t
Clock identifier.
Definition
time.h:21
roc::core::ClockUnix
@ ClockUnix
Real-time Unix-time UTC clock.
Definition
time.h:54
roc::core::ClockMonotonic
@ ClockMonotonic
Virtual monotonic clock.
Definition
time.h:40
roc::core::sleep_for
void sleep_for(clock_t clock, nanoseconds_t duration)
Sleep specified amount of time.
roc::core::Hour
const nanoseconds_t Hour
One hour represented in nanoseconds.
Definition
time.h:76
roc::core::sleep_until
void sleep_until(clock_t clock, nanoseconds_t timestamp)
Sleep until the specified absolute time point has been reached.
roc::core::tm_2_nanoseconds
nanoseconds_t tm_2_nanoseconds(std::tm tm)
Convert timestamp from broken-down time to nanoseconds format.
roc::core::nanoseconds_t
int64_t nanoseconds_t
Nanoseconds.
Definition
time.h:58
roc
Root namespace.
stddefs.h
Commonly used types and functions.
roc_core
time.h
Generated by
1.17.0