libosmocore
0.9.3
Osmocom core library
|
00001 /* 00002 * (C) 2011 Sylvain Munaut <tnt@246tNt.com> 00003 * All Rights Reserved 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 * 00019 */ 00020 00029 #pragma once 00030 00031 00032 /* Convenience macros for operations on timevals. 00033 NOTE: `timercmp' does not work for >= or <=. */ 00034 00035 #ifndef timerisset 00036 # define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 00037 #endif 00038 00039 #ifndef timerclear 00040 # define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 00041 #endif 00042 00043 #ifndef timercmp 00044 # define timercmp(a, b, CMP) \ 00045 (((a)->tv_sec == (b)->tv_sec) ? \ 00046 ((a)->tv_usec CMP (b)->tv_usec) : \ 00047 ((a)->tv_sec CMP (b)->tv_sec)) 00048 #endif 00049 00050 #ifndef timeradd 00051 # define timeradd(a, b, result) \ 00052 do { \ 00053 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 00054 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 00055 if ((result)->tv_usec >= 1000000) \ 00056 { \ 00057 ++(result)->tv_sec; \ 00058 (result)->tv_usec -= 1000000; \ 00059 } \ 00060 } while (0) 00061 #endif 00062 00063 #ifndef timersub 00064 # define timersub(a, b, result) \ 00065 do { \ 00066 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 00067 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 00068 if ((result)->tv_usec < 0) { \ 00069 --(result)->tv_sec; \ 00070 (result)->tv_usec += 1000000; \ 00071 } \ 00072 } while (0) 00073 #endif 00074 00075