libosmocore  0.6.3
Osmocom core library
timer_compat.h
Go to the documentation of this file.
1 /*
2  * (C) 2011 Sylvain Munaut <tnt@246tNt.com>
3  * All Rights Reserved
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  */
20 
29 #ifndef TIMER_COMPAT_H
30 #define TIMER_COMPAT_H
31 
32 
33 /* Convenience macros for operations on timevals.
34  NOTE: `timercmp' does not work for >= or <=. */
35 
36 #ifndef timerisset
37 # define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
38 #endif
39 
40 #ifndef timerclear
41 # define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
42 #endif
43 
44 #ifndef timercmp
45 # define timercmp(a, b, CMP) \
46  (((a)->tv_sec == (b)->tv_sec) ? \
47  ((a)->tv_usec CMP (b)->tv_usec) : \
48  ((a)->tv_sec CMP (b)->tv_sec))
49 #endif
50 
51 #ifndef timeradd
52 # define timeradd(a, b, result) \
53  do { \
54  (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
55  (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
56  if ((result)->tv_usec >= 1000000) \
57  { \
58  ++(result)->tv_sec; \
59  (result)->tv_usec -= 1000000; \
60  } \
61  } while (0)
62 #endif
63 
64 #ifndef timersub
65 # define timersub(a, b, result) \
66  do { \
67  (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
68  (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
69  if ((result)->tv_usec < 0) { \
70  --(result)->tv_sec; \
71  (result)->tv_usec += 1000000; \
72  } \
73  } while (0)
74 #endif
75 
76 
79 #endif /* TIMER_COMPAT_H */