libosmocore
1.5.1
Osmocom core library
timer_compat.h
Go to the documentation of this file.
1
4
/*
5
* (C) 2011 Sylvain Munaut <tnt@246tNt.com>
6
* All Rights Reserved
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License along
19
* with this program; if not, write to the Free Software Foundation, Inc.,
20
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
*
22
*/
23
28
#pragma once
29
30
/* MacOS < 10.12 Sierra does not define clockid_t */
31
#if defined(__APPLE__) && (!defined(__DARWIN_C_LEVEL) || __DARWIN_C_LEVEL < 199309L)
32
typedef
int
clockid_t;
33
#endif
34
35
/* Convenience macros for operations on timevals.
36
NOTE: `timercmp' does not work for >= or <=. */
37
38
#ifndef timerisset
39
# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
40
#endif
41
42
#ifndef timerclear
43
# define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
44
#endif
45
46
#ifndef timercmp
47
# define timercmp(a, b, CMP) \
48
(((a)->tv_sec == (b)->tv_sec) ? \
49
((a)->tv_usec CMP (b)->tv_usec) : \
50
((a)->tv_sec CMP (b)->tv_sec))
51
#endif
52
53
#ifndef timeradd
54
# define timeradd(a, b, result) \
55
do { \
56
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
57
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
58
if ((result)->tv_usec >= 1000000) \
59
{ \
60
++(result)->tv_sec; \
61
(result)->tv_usec -= 1000000; \
62
} \
63
} while (0)
64
#endif
65
66
#ifndef timersub
67
# define timersub(a, b, result) \
68
do { \
69
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
70
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
71
if ((result)->tv_usec < 0) { \
72
--(result)->tv_sec; \
73
(result)->tv_usec += 1000000; \
74
} \
75
} while (0)
76
#endif
77
78
/* Convenience macros for operations on timespecs.
79
NOTE: `timercmp' does not work for >= or <=. */
80
81
#ifndef timespecisset
82
# define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec)
83
#endif
84
85
#ifndef timespecclear
86
# define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0)
87
#endif
88
89
#ifndef timespeccmp
90
# define timespeccmp(a, b, CMP) \
91
(((a)->tv_sec == (b)->tv_sec) ? \
92
((a)->tv_nsec CMP (b)->tv_nsec) : \
93
((a)->tv_sec CMP (b)->tv_sec))
94
#endif
95
96
#ifndef timespecadd
97
# define timespecadd(a, b, result) \
98
do { \
99
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
100
(result)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec; \
101
if ((result)->tv_nsec >= 1000000000) \
102
{ \
103
++(result)->tv_sec; \
104
(result)->tv_nsec -= 1000000000; \
105
} \
106
} while (0)
107
#endif
108
109
#ifndef timespecsub
110
# define timespecsub(a, b, result) \
111
do { \
112
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
113
(result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
114
if ((result)->tv_nsec < 0) { \
115
--(result)->tv_sec; \
116
(result)->tv_nsec += 1000000000; \
117
} \
118
} while (0)
119
#endif
120
121
122
include
osmocom
core
timer_compat.h
Generated by
1.8.18