]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blob - frsh_time.h
Update transaction API
[frescor/frsh-include.git] / frsh_time.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2009 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 static inline frsh_rel_time_t frsh_rel_time_incr(frsh_rel_time_t t1, frsh_rel_time_t t2)
157 {
158     return fosa_rel_time_add(t1, t2);
159 }
160
161
162
163
164 /**
165  * frsh_abs_time_decr
166  *
167  * Subtract a relative interval from an absolute time.
168  */
169 static inline frsh_abs_time_t frsh_abs_time_decr(frsh_abs_time_t time, frsh_rel_time_t interval)
170 {
171     return fosa_abs_time_decr(time, interval);
172 }
173
174 /**
175  * frsh_rel_time_decr()
176  *
177  * Subtract a relative interval from another one.
178  */
179 static inline frsh_rel_time_t frsh_rel_time_decr(frsh_rel_time_t total, frsh_rel_time_t part)
180 {
181     return fosa_rel_time_decr(total, part);
182 }
183     
184
185 /**
186  * frsh_abs_time_extract_interval()
187  * 
188  * Subtract two absolute times to get a relative interval.
189  */
190 static inline frsh_rel_time_t frsh_abs_time_extract_interval(frsh_abs_time_t past, frsh_abs_time_t future)
191 {
192     return fosa_abs_time_extract_interval(past, future);
193 }
194
195
196 static inline frsh_rel_time_t frsh_abs_time_subtract(frsh_abs_time_t past, frsh_abs_time_t future)
197 {
198     return fosa_abs_time_extract_interval(past, future);
199 }
200
201
202
203
204 /**
205  * frsh_rel_time_times_integer()
206  * 
207  * Multiplies a relative time by an integer
208  */
209 static inline frsh_rel_time_t frsh_rel_time_times_integer(frsh_rel_time_t time, long multiplier)
210 {
211     return fosa_rel_time_times_integer(time, multiplier);
212 }
213
214 /**
215  * frsh_rel_time_times_integer()
216  * 
217  * Divides a relative time by an integer
218  **/
219 static inline frsh_rel_time_t frsh_rel_time_divided_by_integer(frsh_rel_time_t time, long divider)
220 {
221     return fosa_rel_time_divided_by_integer(time, divider);
222 }
223
224
225 /************************************
226  * Conversion to-from natural formats
227  * Note: Overflows may occur
228  ************************************/
229
230 /**
231  * frsh_msec_to_rel_time()
232  *
233  * Convert an integer value of milliseconds into a relative time interval.
234  */
235 static inline frsh_rel_time_t frsh_msec_to_rel_time(long msec)
236 {
237     return fosa_msec_to_rel_time(msec);
238 }
239
240 /**
241  * frsh_rel_time_to_msec()
242  *
243  * Convert a relative interval into an integer number of milliseconds.
244  */
245 static inline long frsh_rel_time_to_msec(frsh_rel_time_t interval)
246 {
247     return fosa_rel_time_to_msec(interval);
248 }
249
250 /**
251  * frsh_msec_to_abs_time()
252  *
253  * Convert an integer value of milliseconds into an absolute time instant
254  */
255 static inline frsh_abs_time_t frsh_msec_to_abs_time(long msec)
256 {
257     return fosa_msec_to_abs_time(msec);
258 }
259
260 /**
261  * frsh_abs_time_to_msec()
262  *
263  * Convert an absolute instant into an integer number of milliseconds.
264  */
265 static inline long frsh_abs_time_to_msec(frsh_abs_time_t instant)
266 {
267     return fosa_abs_time_to_msec(instant);
268 }
269
270 /**
271  * frsh_usec_to_rel_time() 
272  *
273  * Convert an integer value of microseconds into an absolute instant.
274  */
275 static inline frsh_rel_time_t frsh_usec_to_rel_time(long usec)
276 {
277     return fosa_usec_to_rel_time(usec);
278 }
279
280
281 /**
282  * frsh_rel_time_to_usec() 
283  *
284  * Convert a relative interval into an integer number of microseconds.
285  */
286 static inline long frsh_rel_time_to_usec(frsh_rel_time_t interval)
287 {
288     return fosa_rel_time_to_usec(interval);
289 }
290
291 /**
292  * frsh_usec_to_abs_time() 
293  *
294  * Convert an integer value of microseconds into an absolute instant.
295  */
296 static inline frsh_abs_time_t frsh_usec_to_abs_time(long usec)
297 {
298     return fosa_usec_to_abs_time(usec);
299 }
300
301
302 /**
303  * frsh_abs_time_to_usec() 
304  *
305  * Convert a relative interval into an integer number of microseconds.
306  */
307 static inline long frsh_abs_time_to_usec(frsh_abs_time_t interval)
308 {
309     return fosa_abs_time_to_usec(interval);
310 }
311
312 /**
313  * frsh_nsec_to_rel_time() 
314  *
315  * Convert an integer value of microseconds into an absolute instant.
316  */
317 static inline frsh_rel_time_t frsh_nsec_to_rel_time(long nsec)
318 {
319     return fosa_nsec_to_rel_time(nsec);
320 }
321
322
323 /**
324  * frsh_rel_time_to_nsec() 
325  *
326  * Convert a relative interval into an integer number of microseconds.
327  */
328 static inline long frsh_rel_time_to_nsec(frsh_rel_time_t interval)
329 {
330     return fosa_rel_time_to_nsec(interval);
331 }
332
333 /**
334  * frsh_nsec_to_abs_time() 
335  *
336  * Convert an integer value of microseconds into an absolute instant.
337  */
338 static inline frsh_abs_time_t frsh_nsec_to_abs_time(long nsec)
339 {
340     return fosa_nsec_to_abs_time(nsec);
341 }
342
343
344 /**
345  * frsh_abs_time_to_nsec() 
346  *
347  * Convert a relative interval into an integer number of microseconds.
348  */
349 static inline long frsh_abs_time_to_nsec(frsh_abs_time_t interval)
350 {
351     return fosa_abs_time_to_nsec(interval);
352 }
353
354 /******************************************
355  * Conversion to-from POSIX timespec format
356  ******************************************/
357
358 /**
359  * frsh_timespec_to_rel_time()
360  * 
361  * Convert a POSIX timespec value into a relative time interval.
362  */
363 static inline frsh_rel_time_t frsh_timespec_to_rel_time(struct timespec interval)
364 {
365     return fosa_timespec_to_rel_time(interval);
366 }
367
368 /**
369  * frsh_rel_time_to_timespec() 
370  *
371  * Convert a relative interval into a POSIX timespec value.
372  */
373 static inline struct timespec frsh_rel_time_to_timespec(frsh_rel_time_t interval)
374 {
375     return fosa_rel_time_to_timespec(interval);
376 }
377
378 /**
379  * frsh_timespec_to_abs_time()
380  * 
381  * Convert a POSIX timespec value into an absolute time.
382  */
383 static inline frsh_abs_time_t frsh_timespec_to_abs_time(struct timespec time)
384 {
385     return fosa_timespec_to_abs_time(time);
386 }
387
388 /**
389  * frsh_abs_time_to_timespec()
390  * 
391  * Convert an absolute time into a POSIX timespec value.
392  */
393 static inline struct timespec frsh_abs_time_to_timespec(frsh_abs_time_t time)
394 {
395     return fosa_abs_time_to_timespec(time);
396 }
397
398
399 /**
400  * frsh_eat()
401  *
402  * Keep the thread busy executing for a given period of time.
403  **/
404 static inline void  frsh_eat(frsh_rel_time_t *cpu_time)
405 {
406     fosa_eat(cpu_time);
407 }
408
409 /*@}*/
410
411 FRSH_CPP_END_DECLS
412
413 #endif      /* !FOSA_TIME_H_ */