1 /*----------------------------------------------------------------------------
2 *------------------------- M a R T E O S ------------------------
3 *----------------------------------------------------------------------------
6 * 't i m e s p e c _ o p e r a t i o n s'
10 * File 'timespec_operations.h' by MAR.
11 * (july 2002) transformed into macros by Jul.
12 * Some basic operations with the type 'timespec'.
14 * ----------------------------------------------------------------------
15 * Copyright (C) 2001 Universidad de Cantabria, SPAIN
17 * Authors: Mario Aldea Rivas aldeam@ctr.unican.es
18 * Michael Gonzalez Harbour mgh@ctr.unican.es
20 * MaRTE OS is free software; you can redistribute it and/or modify it
21 * under the terms of the GNU General Public License as published by the
22 * Free Software Foundation; either version 2, or (at your option) any
25 * MaRTE OS is distributed in the hope that it will be useful, but
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * distributed with MaRTE OS; see file COPYING. If not, write to the
32 * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
35 * As a special exception, if you link this unit with other files to
36 * produce an executable, this unit does not by itself cause the
37 * resulting executable to be covered by the GNU General Public License.
38 * This exception does not however invalidate any other reasons why the
39 * executable file might be covered by the GNU Public License.
41 *---------------------------------------------------------------------------*/
43 #ifndef _MARTE_MISC_TIMESPEC_OPERATIONS_H_
44 #define _MARTE_MISC_TIMESPEC_OPERATIONS_H_
48 #define smaller_timespec(t1, t2) \
50 (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \
51 (t1)->tv_nsec < (t2)->tv_nsec) \
54 #define smaller_or_equal_timespec(t1, t2) \
56 (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \
57 (t1)->tv_nsec <= (t2)->tv_nsec) \
60 #define incr_timespec(t1, t2) \
62 (t1)->tv_sec += (t2)->tv_sec; \
63 (t1)->tv_nsec += (t2)->tv_nsec; \
64 if ((t1)->tv_nsec >= 1000000000) { \
66 (t1)->tv_nsec -= 1000000000; \
70 #define decr_timespec(t1, t2) \
72 if ((t1)->tv_nsec < (t2)->tv_nsec) { \
73 (t1)->tv_sec -= (t2)->tv_sec + 1; \
74 (t1)->tv_nsec = (t1)->tv_nsec + 1000000000 - (t2)->tv_nsec; \
76 (t1)->tv_sec -= (t2)->tv_sec; \
77 (t1)->tv_nsec -= (t2)->tv_nsec; \
82 #define add_timespec( sum , t1 , t2 ) \
84 (sum)->tv_sec = (t1)->tv_sec + (t2)->tv_sec; \
85 (sum)->tv_nsec = (t1)->tv_nsec + (t2)->tv_nsec; \
86 if ((sum)->tv_nsec >= 1000000000) { \
88 (sum)->tv_nsec -= 1000000000; \
92 #define float_to_timespec( f1 , t1 ) \
94 (t1)->tv_sec = (int)(f1), \
95 (t1)->tv_nsec = (int)(((f1)-(float)((t1)->tv_sec))*1000000000.0), \
99 #define float_to_timespec_value(f1, t1) \
101 (t1).tv_sec = (int)(f1), \
102 (t1).tv_nsec = (int)(((f1)-(float)((t1).tv_sec))*1000000000.0), \
106 #endif /* _MARTE_MISC_TIMESPEC_OPERATIONS_H_ */