23 #ifndef _ASTERISK_TIME_H
24 #define _ASTERISK_TIME_H
26 #ifdef HAVE_SYS_TIME_H
35 extern struct timeval
tv;
36 typedef typeof(
tv.tv_sec) ast_time_t;
37 typedef
typeof(
tv.tv_usec) ast_suseconds_t;
48 int64_t result = end.tv_sec - start.tv_sec;
49 if (result > 0 && end.tv_usec < start.tv_usec)
51 else if (result < 0 && end.tv_usec > start.tv_usec)
65 int64_t
ast_tvdiff_us(
struct timeval end,
struct timeval start),
67 return (end.tv_sec - start.tv_sec) * (int64_t) 1000000 +
68 end.tv_usec - start.tv_usec;
79 int64_t
ast_tvdiff_ms(
struct timeval end,
struct timeval start),
86 int64_t sec_dif = (int64_t)(end.tv_sec - start.tv_sec) * 1000;
87 int64_t usec_dif = (1000000 + end.tv_usec - start.tv_usec) / 1000 - 1000;
88 return sec_dif + usec_dif;
98 return (t.tv_sec == 0 && t.tv_usec == 0);
107 int ast_tvcmp(
struct timeval _a,
struct timeval _b),
109 if (_a.tv_sec < _b.tv_sec)
111 if (_a.tv_sec > _b.tv_sec)
114 if (_a.tv_usec < _b.tv_usec)
116 if (_a.tv_usec > _b.tv_usec)
126 int ast_tveq(
struct timeval _a,
struct timeval _b),
128 return (_a.tv_sec == _b.tv_sec && _a.tv_usec == _b.tv_usec);
139 gettimeofday(&t, NULL);
147 struct timeval
ast_tvadd(
struct timeval a,
struct timeval b);
152 struct timeval
ast_tvsub(struct timeval a, struct timeval b);
172 struct timeval
ast_tv(ast_time_t sec, ast_suseconds_t usec),
187 struct timeval
ast_samp2tv(
unsigned int _nsamp,
unsigned int _rate),
189 return ast_tv(_nsamp / _rate, ((_nsamp % _rate) * (4000000 / _rate)) / 4);
typedef typeof(tv.tv_sec) ast_time_t
int ast_tveq(struct timeval _a, struct timeval _b)
Returns true if the two struct timeval arguments are equal.
int64_t ast_tvdiff_sec(struct timeval end, struct timeval start)
Computes the difference (in seconds) between two struct timeval instances.
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Inlinable API function macro.
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
int ast_tvcmp(struct timeval _a, struct timeval _b)
Compres two struct timeval instances returning -1, 0, 1 if the first arg is smaller, equal or greater to the second.
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
#define AST_INLINE_API(hdr, body)