blob: fb2967bad0f9afa1dfa96078be4e223c29cb81bd [file] [log] [blame]
Sylvain Munaut07f11032011-10-21 21:55:29 +02001/*
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
21/*! \defgroup timer Osmocom timers
22 * @{
23 */
24
25/*! \file timer_compat.h
26 * \brief Compatibility header with some helpers
27 */
28
Sylvain Munaut12ba7782014-06-16 10:13:40 +020029#pragma once
Sylvain Munaut07f11032011-10-21 21:55:29 +020030
31
32/* Convenience macros for operations on timevals.
33 NOTE: `timercmp' does not work for >= or <=. */
34
35#ifndef timerisset
36# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
37#endif
38
39#ifndef timerclear
40# define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
41#endif
42
43#ifndef timercmp
44# define timercmp(a, b, CMP) \
45 (((a)->tv_sec == (b)->tv_sec) ? \
46 ((a)->tv_usec CMP (b)->tv_usec) : \
47 ((a)->tv_sec CMP (b)->tv_sec))
48#endif
49
50#ifndef timeradd
51# define timeradd(a, b, result) \
52 do { \
53 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
54 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
55 if ((result)->tv_usec >= 1000000) \
56 { \
57 ++(result)->tv_sec; \
58 (result)->tv_usec -= 1000000; \
59 } \
60 } while (0)
61#endif
62
63#ifndef timersub
64# define timersub(a, b, result) \
65 do { \
66 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
67 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
68 if ((result)->tv_usec < 0) { \
69 --(result)->tv_sec; \
70 (result)->tv_usec += 1000000; \
71 } \
72 } while (0)
73#endif
74
75
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020076/*! @} */