]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blob - frsh_time.h
Merging the frsh_sa branch in the trunk.
[frescor/frsh-include.git] / frsh_time.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 //frsh_spare_capacity_types.h
59 //==============================================
60 //  ******** *******    ********  **      **
61 //  **///// /**////**  **//////  /**     /**
62 //  **      /**   /** /**        /**     /**
63 //  ******* /*******  /********* /**********
64 //  **////  /**///**  ////////** /**//////**
65 //  **      /**  //**        /** /**     /**
66 //  **      /**   //** ********  /**     /**
67 //  //       //     // ////////   //      // 
68 //
69 // FRSH(FRescor ScHeduler), pronounced "fresh"
70 //==============================================
71
72 #ifndef         FRSH_TIME_H_
73 #define         FRSH_TIME_H_
74
75 #include "frsh_core_types.h"
76 #include "frsh_core.h"
77
78 FRSH_CPP_BEGIN_DECLS
79
80 /**
81  * @file frsh_time.h
82  **/
83
84
85 /**
86  * \addtogroup core
87  **/
88 /*@{*/
89
90 /***********************
91  * Relational operations
92  ***********************/  
93
94 /**
95  * frsh_abs_time_smaller()
96  *
97  * Check if an absolute time is smaller than another one.
98  **/
99 static inline bool frsh_abs_time_smaller(frsh_abs_time_t t1, frsh_abs_time_t t2)
100 {
101     return fosa_abs_time_smaller(t1, t2);
102 }
103
104 /**
105  * frsh_rel_time_smaller()
106  *
107  * Check if a relative interval is smaller than another one.
108  **/
109 static inline bool frsh_rel_time_smaller(frsh_rel_time_t t1, frsh_rel_time_t t2)
110 {
111     return fosa_rel_time_smaller(t1, t2);
112 }
113
114 /**
115  * frsh_abs_time_smaller_or_equal()
116  *
117  * Check if an absolute time is smaller than or equal to another one.
118  **/
119 static inline bool frsh_abs_time_smaller_or_equal(frsh_abs_time_t t1, frsh_abs_time_t t2)
120 {
121     return fosa_abs_time_smaller_or_equal(t1, t2);
122 }
123
124 /**
125  * frsh_rel_time_smaller_or_equal()
126  *
127  * Check if a relative interval is smaller than or equal to another one.
128  **/
129 static inline bool frsh_rel_time_smaller_or_equal(frsh_rel_time_t t1, frsh_rel_time_t t2)
130 {
131     return fosa_rel_time_smaller_or_equal(t1, t2);
132 }
133
134
135 /***********************
136  * Arithmetic operations
137  ***********************/  
138
139 /**
140  * frsh_abs_time_incr()
141  *
142  * Add a relative interval to an absolute time.
143  */
144 static inline frsh_abs_time_t frsh_abs_time_incr(frsh_abs_time_t base, frsh_rel_time_t interval)
145 {
146     return fosa_abs_time_incr(base, interval);
147 }
148
149 /**
150  * frsh_rel_time_add()
151  *
152  * Add a relative interval to another one.
153  */
154 static inline frsh_rel_time_t frsh_rel_time_add(frsh_rel_time_t t1, frsh_rel_time_t t2)
155 {
156     return fosa_rel_time_add(t1, t2);
157 }
158
159 /**
160  * frsh_abs_time_decr
161  *
162  * Subtract a relative interval from an absolute time.
163  */
164 static inline frsh_abs_time_t frsh_abs_time_decr(frsh_abs_time_t time, frsh_rel_time_t interval)
165 {
166     return fosa_abs_time_decr(time, interval);
167 }
168
169 /**
170  * frsh_rel_time_decr()
171  *
172  * Subtract a relative interval from another one.
173  */
174 static inline frsh_rel_time_t frsh_rel_time_decr(frsh_rel_time_t total, frsh_rel_time_t part)
175 {
176     return fosa_rel_time_decr(total, part);
177 }
178     
179
180 /**
181  * frsh_abs_time_extract_interval()
182  * 
183  * Subtract two absolute times to get a relative interval.
184  */
185 static inline frsh_rel_time_t frsh_abs_time_extract_interval(frsh_abs_time_t past, frsh_abs_time_t future)
186 {
187     return fosa_abs_time_extract_interval(past, future);
188 }
189
190 /**
191  * frsh_rel_time_times_integer()
192  * 
193  * Multiplies a relative time by an integer
194  */
195 static inline frsh_rel_time_t frsh_rel_time_times_integer(frsh_rel_time_t time, long multiplier)
196 {
197     return fosa_rel_time_times_integer(time, multiplier);
198 }
199
200 /**
201  * frsh_rel_time_times_integer()
202  * 
203  * Multiplies a relative time by an integer
204  **/
205 static inline frsh_rel_time_t frsh_rel_time_divided_by_integer(frsh_rel_time_t time, long divider)
206 {
207     return fosa_rel_time_divided_by_integer(time, divider);
208 }
209
210
211 /************************************
212  * Conversion to-from natural formats
213  * Note: Overflows may occur
214  ************************************/
215
216 /**
217  * frsh_msec_to_rel_time()
218  *
219  * Convert an integer value of milliseconds into a relative time interval.
220  */
221 static inline frsh_rel_time_t frsh_msec_to_rel_time(long msec)
222 {
223     return fosa_msec_to_rel_time(msec);
224 }
225
226 /**
227  * frsh_rel_time_to_msec()
228  *
229  * Convert a relative interval into an integer number of milliseconds.
230  */
231 static inline long frsh_rel_time_to_msec(frsh_rel_time_t interval)
232 {
233     return fosa_rel_time_to_msec(interval);
234 }
235
236 /**
237  * frsh_msec_to_abs_time()
238  *
239  * Convert an integer value of milliseconds into an absolute time instant
240  */
241 static inline frsh_abs_time_t frsh_msec_to_abs_time(long msec)
242 {
243     return fosa_msec_to_abs_time(msec);
244 }
245
246 /**
247  * frsh_abs_time_to_msec()
248  *
249  * Convert an absolute instant into an integer number of milliseconds.
250  */
251 static inline long frsh_abs_time_to_msec(frsh_abs_time_t instant)
252 {
253     return fosa_abs_time_to_msec(instant);
254 }
255
256 /**
257  * frsh_usec_to_rel_time() 
258  *
259  * Convert an integer value of microseconds into an absolute instant.
260  */
261 static inline frsh_rel_time_t frsh_usec_to_rel_time(long usec)
262 {
263     return fosa_usec_to_rel_time(usec);
264 }
265
266
267 /**
268  * frsh_rel_time_to_usec() 
269  *
270  * Convert a relative interval into an integer number of microseconds.
271  */
272 static inline long frsh_rel_time_to_usec(frsh_rel_time_t interval)
273 {
274     return fosa_rel_time_to_usec(interval);
275 }
276
277 /**
278  * frsh_usec_to_abs_time() 
279  *
280  * Convert an integer value of microseconds into an absolute instant.
281  */
282 static inline frsh_abs_time_t frsh_usec_to_abs_time(long usec)
283 {
284     return fosa_usec_to_abs_time(usec);
285 }
286
287
288 /**
289  * frsh_abs_time_to_usec() 
290  *
291  * Convert a relative interval into an integer number of microseconds.
292  */
293 static inline long frsh_abs_time_to_usec(frsh_abs_time_t interval)
294 {
295     return fosa_abs_time_to_usec(interval);
296 }
297
298 /******************************************
299  * Conversion to-from POSIX timespec format
300  ******************************************/
301
302 /**
303  * frsh_timespec_to_rel_time()
304  * 
305  * Convert a POSIX timespec value into a relative time interval.
306  */
307 static inline frsh_rel_time_t frsh_timespec_to_rel_time(struct timespec interval)
308 {
309     return fosa_timespec_to_rel_time(interval);
310 }
311
312 /**
313  * frsh_rel_time_to_timespec() 
314  *
315  * Convert a relative interval into a POSIX timespec value.
316  */
317 static inline struct timespec frsh_rel_time_to_timespec(frsh_rel_time_t interval)
318 {
319     return fosa_rel_time_to_timespec(interval);
320 }
321
322 /**
323  * frsh_timespec_to_abs_time()
324  * 
325  * Convert a POSIX timespec value into an absolute time.
326  */
327 static inline frsh_abs_time_t frsh_timespec_to_abs_time(struct timespec time)
328 {
329     return fosa_timespec_to_abs_time(time);
330 }
331
332 /**
333  * frsh_abs_time_to_timespec()
334  * 
335  * Convert an absolute time into a POSIX timespec value.
336  */
337 static inline struct timespec frsh_abs_time_to_timespec(frsh_abs_time_t time)
338 {
339     return fosa_abs_time_to_timespec(time);
340 }
341
342
343 /**
344  * frsh_eat()
345  *
346  * Keep the thread busy executing for a given period of time.
347  **/
348 static inline void  frsh_eat(frsh_rel_time_t *cpu_time)
349 {
350     fosa_eat(cpu_time);
351 }
352
353 /*@}*/
354
355 FRSH_CPP_END_DECLS
356
357 #endif      /* !FOSA_TIME_H_ */