]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blob - timespec_operations.h
Updating FRSH textlogo
[frescor/frsh-include.git] / timespec_operations.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
3 //
4 //    Universidad de Cantabria,              SPAIN
5 //    University of York,                    UK
6 //    Scuola Superiore Sant'Anna,            ITALY
7 //    Kaiserslautern University,             GERMANY
8 //    Univ. Politécnica  Valencia,           SPAIN
9 //    Czech Technical University in Prague,  CZECH REPUBLIC
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //    
16 //    See http://www.frescor.org for a link to partners' websites
17 //
18 //           FRESCOR project (FP6/2005/IST/5-034026) is funded
19 //        in part by the European Union Sixth Framework Programme
20 //        The European Union is not liable of any use that may be
21 //        made of this code.
22 //
23 //
24 //  based on previous work (FSF) done in the FIRST project
25 //                       
26 //   Copyright (C) 2005  Mälardalen University, SWEDEN
27 //                       Scuola Superiore S.Anna, ITALY
28 //                       Universidad de Cantabria, SPAIN
29 //                       University of York, UK
30 //
31 //   FSF API web pages: http://marte.unican.es/fsf/docs
32 //                      http://shark.sssup.it/contrib/first/docs/
33 //
34 //  This file is part of FRSH API
35 //
36 //  FRSH API is free software; you can  redistribute it and/or  modify
37 //  it under the terms of  the GNU General Public License as published by
38 //  the Free Software Foundation;  either  version 2, or (at  your option)
39 //  any later version.
40 //
41 //  FRSH API  is distributed  in  the hope  that  it  will  be useful,  but
42 //  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
43 //  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
44 //  General Public License for more details.
45 //
46 //  You should have  received a  copy of  the  GNU  General Public License
47 //  distributed  with  FRSH API;  see file COPYING.   If not,  write to the
48 //  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
49 //  02111-1307, USA.
50 //
51 //  As a special exception, if you include this header file into source
52 //  files to be compiled, this header file does not by itself cause
53 //  the resulting executable to be covered by the GNU General Public
54 //  License.  This exception does not however invalidate any other
55 //  reasons why the executable file might be covered by the GNU General
56 //  Public License.
57 // -----------------------------------------------------------------------
58  *                                                           V1.0  Dec 2001
59  *
60  *                    't i m e s p e c _ o p e r a t i o n s'
61  *
62  *                                      H
63  *
64  * File 'timespec_operations.h'                                        by MAR.
65  *                                (july 2002)  transformed into macros by Jul.
66  * Some basic operations with the type 'timespec'.
67  *
68  * ----------------------------------------------------------------------
69  *  Copyright (C) 2001   Universidad de Cantabria, SPAIN
70  *
71  *  Authors: Mario Aldea Rivas          aldeam@ctr.unican.es
72  *           Michael Gonzalez Harbour      mgh@ctr.unican.es
73  *
74  * MaRTE OS  is free software; you can  redistribute it and/or  modify it
75  * under the terms of the GNU General Public License  as published by the
76  * Free Software Foundation;  either  version 2, or (at  your option) any
77  * later version.
78  *
79  * MaRTE OS  is distributed  in the  hope  that  it will be   useful, but
80  * WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
81  * MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
82  * General Public License for more details.
83  *
84  * You should have received  a  copy of  the  GNU General Public  License
85  * distributed with MaRTE  OS;  see file COPYING.   If not,  write to the
86  * Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
87  * 02111-1307, USA.
88  *
89  * As a  special exception, if you  link this  unit  with other  files to
90  * produce an   executable,   this unit  does  not  by  itself cause  the
91  * resulting executable to be covered by the  GNU General Public License.
92  * This exception does  not however invalidate  any other reasons why the
93  * executable file might be covered by the GNU Public License.
94  *
95  *---------------------------------------------------------------------------*/
96
97 #ifndef _MARTE_MISC_TIMESPEC_OPERATIONS_H_
98 #define _MARTE_MISC_TIMESPEC_OPERATIONS_H_
99
100 #include <time.h>
101
102 #define smaller_timespec(t1, t2) \
103  ( \
104   (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec &&   \
105                                      (t1)->tv_nsec < (t2)->tv_nsec) \
106  )
107
108 #define smaller_or_equal_timespec(t1, t2) \
109  ( \
110   (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec &&    \
111                                      (t1)->tv_nsec <= (t2)->tv_nsec) \
112  )
113
114 #define incr_timespec(t1, t2) \
115 { \
116   (t1)->tv_sec += (t2)->tv_sec; \
117   (t1)->tv_nsec += (t2)->tv_nsec; \
118   if ((t1)->tv_nsec >= 1000000000) { \
119     (t1)->tv_sec ++; \
120     (t1)->tv_nsec -= 1000000000; \
121   } \
122 }
123
124 #define decr_timespec(t1, t2) \
125 { \
126   if ((t1)->tv_nsec < (t2)->tv_nsec) { \
127     (t1)->tv_sec -= (t2)->tv_sec + 1; \
128     (t1)->tv_nsec = (t1)->tv_nsec + 1000000000 - (t2)->tv_nsec; \
129   } else { \
130     (t1)->tv_sec -= (t2)->tv_sec; \
131     (t1)->tv_nsec -= (t2)->tv_nsec; \
132   } \
133 }
134
135
136 #define  add_timespec( sum , t1 , t2 ) \
137 { \
138   (sum)->tv_sec  = (t1)->tv_sec  + (t2)->tv_sec; \
139   (sum)->tv_nsec = (t1)->tv_nsec + (t2)->tv_nsec; \
140   if ((sum)->tv_nsec >= 1000000000) { \
141     (sum)->tv_sec ++; \
142     (sum)->tv_nsec -= 1000000000; \
143   } \
144 }
145
146 #define float_to_timespec( f1 , t1 ) \
147 ( \
148   (t1)->tv_sec = (int)(f1), \
149   (t1)->tv_nsec = (int)(((f1)-(float)((t1)->tv_sec))*1000000000.0), \
150   (t1) \
151 )
152
153 #define float_to_timespec_value(f1, t1) \
154 ( \
155   (t1).tv_sec = (int)(f1), \
156   (t1).tv_nsec = (int)(((f1)-(float)((t1).tv_sec))*1000000000.0), \
157   (t1) \
158 )
159
160 #endif /* _MARTE_MISC_TIMESPEC_OPERATIONS_H_ */