]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blob - frsh_time.h
Modified Makefile.omk to support frsh_forb targets
[frescor/frsh-include.git] / frsh_time.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2008 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 (FRescor ScHeduler)
35 //
36 //  FRSH is free software; you can redistribute it and/or modify it
37 //  under terms of the GNU General Public License as published by the
38 //  Free Software Foundation; either version 2, or (at your option) any
39 //  later version.  FRSH is distributed in the hope that it will be
40 //  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
41 //  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 //  General Public License for more details. You should have received a
43 //  copy of the GNU General Public License along with FRSH; see file
44 //  COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
45 //  Cambridge, MA 02139, USA.
46 //
47 //  As a special exception, including FRSH header files in a file,
48 //  instantiating FRSH generics or templates, or linking other files
49 //  with FRSH objects to produce an executable application, does not
50 //  by itself cause the resulting executable application to be covered
51 //  by the GNU General Public License. This exception does not
52 //  however invalidate any other reasons why the executable file might be
53 //  covered by the GNU Public License.
54 // -----------------------------------------------------------------------
55 //frsh_spare_capacity_types.h
56 //==============================================
57 //  ******** *******    ********  **      **
58 //  **///// /**////**  **//////  /**     /**
59 //  **      /**   /** /**        /**     /**
60 //  ******* /*******  /********* /**********
61 //  **////  /**///**  ////////** /**//////**
62 //  **      /**  //**        /** /**     /**
63 //  **      /**   //** ********  /**     /**
64 //  //       //     // ////////   //      // 
65 //
66 // FRSH(FRescor ScHeduler), pronounced "fresh"
67 //==============================================
68
69 #ifndef         FRSH_TIME_H_
70 #define         FRSH_TIME_H_
71
72 #include "frsh_core_types.h"
73 #include "frsh_core.h"
74
75 FRSH_CPP_BEGIN_DECLS
76
77 /**
78  * @file frsh_time.h
79  **/
80
81
82 /**
83  * \addtogroup core
84  **/
85 /*@{*/
86
87 /***********************
88  * Relational operations
89  ***********************/  
90
91 /**
92  * frsh_abs_time_smaller()
93  *
94  * Check if an absolute time is smaller than another one.
95  **/
96 static inline bool frsh_abs_time_smaller(frsh_abs_time_t t1, frsh_abs_time_t t2)
97 {
98     return fosa_abs_time_smaller(t1, t2);
99 }
100
101 /**
102  * frsh_rel_time_smaller()
103  *
104  * Check if a relative interval is smaller than another one.
105  **/
106 static inline bool frsh_rel_time_smaller(frsh_rel_time_t t1, frsh_rel_time_t t2)
107 {
108     return fosa_rel_time_smaller(t1, t2);
109 }
110
111 /**
112  * frsh_abs_time_smaller_or_equal()
113  *
114  * Check if an absolute time is smaller than or equal to another one.
115  **/
116 static inline bool frsh_abs_time_smaller_or_equal(frsh_abs_time_t t1, frsh_abs_time_t t2)
117 {
118     return fosa_abs_time_smaller_or_equal(t1, t2);
119 }
120
121 /**
122  * frsh_rel_time_smaller_or_equal()
123  *
124  * Check if a relative interval is smaller than or equal to another one.
125  **/
126 static inline bool frsh_rel_time_smaller_or_equal(frsh_rel_time_t t1, frsh_rel_time_t t2)
127 {
128     return fosa_rel_time_smaller_or_equal(t1, t2);
129 }
130
131
132 /***********************
133  * Arithmetic operations
134  ***********************/  
135
136 /**
137  * frsh_abs_time_incr()
138  *
139  * Add a relative interval to an absolute time.
140  */
141 static inline frsh_abs_time_t frsh_abs_time_incr(frsh_abs_time_t base, frsh_rel_time_t interval)
142 {
143     return fosa_abs_time_incr(base, interval);
144 }
145
146 /**
147  * frsh_rel_time_add()
148  *
149  * Add a relative interval to another one.
150  */
151 static inline frsh_rel_time_t frsh_rel_time_add(frsh_rel_time_t t1, frsh_rel_time_t t2)
152 {
153     return fosa_rel_time_add(t1, t2);
154 }
155
156 /**
157  * frsh_abs_time_decr
158  *
159  * Subtract a relative interval from an absolute time.
160  */
161 static inline frsh_abs_time_t frsh_abs_time_decr(frsh_abs_time_t time, frsh_rel_time_t interval)
162 {
163     return fosa_abs_time_decr(time, interval);
164 }
165
166 /**
167  * frsh_rel_time_decr()
168  *
169  * Subtract a relative interval from another one.
170  */
171 static inline frsh_rel_time_t frsh_rel_time_decr(frsh_rel_time_t total, frsh_rel_time_t part)
172 {
173     return fosa_rel_time_decr(total, part);
174 }
175     
176
177 /**
178  * frsh_abs_time_extract_interval()
179  * 
180  * Subtract two absolute times to get a relative interval.
181  */
182 static inline frsh_rel_time_t frsh_abs_time_extract_interval(frsh_abs_time_t past, frsh_abs_time_t future)
183 {
184     return fosa_abs_time_extract_interval(past, future);
185 }
186
187 /**
188  * frsh_rel_time_times_integer()
189  * 
190  * Multiplies a relative time by an integer
191  */
192 static inline frsh_rel_time_t frsh_rel_time_times_integer(frsh_rel_time_t time, long multiplier)
193 {
194     return fosa_rel_time_times_integer(time, multiplier);
195 }
196
197 /**
198  * frsh_rel_time_times_integer()
199  * 
200  * Multiplies a relative time by an integer
201  **/
202 static inline frsh_rel_time_t frsh_rel_time_divided_by_integer(frsh_rel_time_t time, long divider)
203 {
204     return fosa_rel_time_divided_by_integer(time, divider);
205 }
206
207
208 /************************************
209  * Conversion to-from natural formats
210  * Note: Overflows may occur
211  ************************************/
212
213 /**
214  * frsh_msec_to_rel_time()
215  *
216  * Convert an integer value of milliseconds into a relative time interval.
217  */
218 static inline frsh_rel_time_t frsh_msec_to_rel_time(long msec)
219 {
220     return fosa_msec_to_rel_time(msec);
221 }
222
223 /**
224  * frsh_rel_time_to_msec()
225  *
226  * Convert a relative interval into an integer number of milliseconds.
227  */
228 static inline long frsh_rel_time_to_msec(frsh_rel_time_t interval)
229 {
230     return fosa_rel_time_to_msec(interval);
231 }
232
233 /**
234  * frsh_msec_to_abs_time()
235  *
236  * Convert an integer value of milliseconds into an absolute time instant
237  */
238 static inline frsh_abs_time_t frsh_msec_to_abs_time(long msec)
239 {
240     return fosa_msec_to_abs_time(msec);
241 }
242
243 /**
244  * frsh_abs_time_to_msec()
245  *
246  * Convert an absolute instant into an integer number of milliseconds.
247  */
248 static inline long frsh_abs_time_to_msec(frsh_abs_time_t instant)
249 {
250     return fosa_abs_time_to_msec(instant);
251 }
252
253 /**
254  * frsh_usec_to_rel_time() 
255  *
256  * Convert an integer value of microseconds into an absolute instant.
257  */
258 static inline frsh_rel_time_t frsh_usec_to_rel_time(long usec)
259 {
260     return fosa_usec_to_rel_time(usec);
261 }
262
263
264 /**
265  * frsh_rel_time_to_usec() 
266  *
267  * Convert a relative interval into an integer number of microseconds.
268  */
269 static inline long frsh_rel_time_to_usec(frsh_rel_time_t interval)
270 {
271     return fosa_rel_time_to_usec(interval);
272 }
273
274 /**
275  * frsh_usec_to_abs_time() 
276  *
277  * Convert an integer value of microseconds into an absolute instant.
278  */
279 static inline frsh_abs_time_t frsh_usec_to_abs_time(long usec)
280 {
281     return fosa_usec_to_abs_time(usec);
282 }
283
284
285 /**
286  * frsh_abs_time_to_usec() 
287  *
288  * Convert a relative interval into an integer number of microseconds.
289  */
290 static inline long frsh_abs_time_to_usec(frsh_abs_time_t interval)
291 {
292     return fosa_abs_time_to_usec(interval);
293 }
294
295 /******************************************
296  * Conversion to-from POSIX timespec format
297  ******************************************/
298
299 /**
300  * frsh_timespec_to_rel_time()
301  * 
302  * Convert a POSIX timespec value into a relative time interval.
303  */
304 static inline frsh_rel_time_t frsh_timespec_to_rel_time(struct timespec interval)
305 {
306     return fosa_timespec_to_rel_time(interval);
307 }
308
309 /**
310  * frsh_rel_time_to_timespec() 
311  *
312  * Convert a relative interval into a POSIX timespec value.
313  */
314 static inline struct timespec frsh_rel_time_to_timespec(frsh_rel_time_t interval)
315 {
316     return fosa_rel_time_to_timespec(interval);
317 }
318
319 /**
320  * frsh_timespec_to_abs_time()
321  * 
322  * Convert a POSIX timespec value into an absolute time.
323  */
324 static inline frsh_abs_time_t frsh_timespec_to_abs_time(struct timespec time)
325 {
326     return fosa_timespec_to_abs_time(time);
327 }
328
329 /**
330  * frsh_abs_time_to_timespec()
331  * 
332  * Convert an absolute time into a POSIX timespec value.
333  */
334 static inline struct timespec frsh_abs_time_to_timespec(frsh_abs_time_t time)
335 {
336     return fosa_abs_time_to_timespec(time);
337 }
338
339
340 /**
341  * frsh_eat()
342  *
343  * Keep the thread busy executing for a given period of time.
344  **/
345 static inline void  frsh_eat(frsh_rel_time_t *cpu_time)
346 {
347     fosa_eat(cpu_time);
348 }
349
350 /*@}*/
351
352 FRSH_CPP_END_DECLS
353
354 #endif      /* !FOSA_TIME_H_ */