]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - include/fosa_time_timespec.h
add incr timespec
[frescor/fosa.git] / include / fosa_time_timespec.h
index 942d9e5515f1f0246557aff3f21ea69a19216af3..77ce73eb8482de38b6fa515dc2caac9671dfa8b4 100644 (file)
@@ -1,11 +1,11 @@
-//----------------------------------------------------------------------
-//  Copyright (C) 2006 - 2007 by the FRESCOR consortium:
+// -----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
 //
 //    Universidad de Cantabria,              SPAIN
 //    University of York,                    UK
 //    Scuola Superiore Sant'Anna,            ITALY
 //    Kaiserslautern University,             GERMANY
-//    Univ. Politecnica  Valencia,           SPAIN
+//    Univ. Politécnica  Valencia,           SPAIN
 //    Czech Technical University in Prague,  CZECH REPUBLIC
 //    ENEA                                   SWEDEN
 //    Thales Communication S.A.              FRANCE
@@ -13,9 +13,9 @@
 //    Rapita Systems Ltd                     UK
 //    Evidence                               ITALY
 //
-//    See http://www.frescor.org
+//    See http://www.frescor.org for a link to partners' websites
 //
-//        The FRESCOR project (FP6/2005/IST/5-034026) is funded
+//           FRESCOR project (FP6/2005/IST/5-034026) is funded
 //        in part by the European Union Sixth Framework Programme
 //        The European Union is not liable of any use that may be
 //        made of this code.
 //                       Universidad de Cantabria, SPAIN
 //                       University of York, UK
 //
-// This file is part of FOSA (Frsh Operating System Abstraction)
+//   FSF API web pages: http://marte.unican.es/fsf/docs
+//                      http://shark.sssup.it/contrib/first/docs/
+//
+//   This file is part of FOSA (Frsh Operating System Adaption)
 //
-// FOSA is free software; you can redistribute it and/or modify it
-// under terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option) any
-// later version.  FOSA is distributed in the hope that it will be
-// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details. You should have received a
-// copy of the GNU General Public License along with FOSA; see file
-// COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
-// Cambridge, MA 02139, USA.
+//  FOSA is free software; you can redistribute it and/or modify it
+//  under terms of the GNU General Public License as published by the
+//  Free Software Foundation; either version 2, or (at your option) any
+//  later version.  FOSA is distributed in the hope that it will be
+//  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//  General Public License for more details. You should have received a
+//  copy of the GNU General Public License along with FOSA; see file
+//  COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+//  Cambridge, MA 02139, USA.
 //
-// As a special exception, including FOSA header files in a file,
-// instantiating FOSA generics or templates, or linking other files
-// with FOSA objects to produce an executable application, does not
-// by itself cause the resulting executable application to be covered
-// by the GNU General Public License. This exception does not
-// however invalidate any other reasons why the executable file might be
-// covered by the GNU Public License.
+//  As a special exception, including FOSA header files in a file,
+//  instantiating FOSA generics or templates, or linking other files
+//  with FOSA objects to produce an executable application, does not
+//  by itself cause the resulting executable application to be covered
+//  by the GNU General Public License. This exception does not
+//  however invalidate any other reasons why the executable file might be
+//  covered by the GNU Public License.
 // -----------------------------------------------------------------------
 //fosa_time_timespec.h
 //==============================================
@@ -58,7 +61,7 @@
 //  **////  /**    ** ////////** /**//////**
 //  **      /**    **        /** /**     /**
 //  **      /**    **  ********  /**     /**
-//  //       /******/  ////////   //      // 
+//  //       /******/  ////////   //      //
 //
 // FOSA(Frescor Operating System Adaptation layer)
 //================================================
@@ -82,7 +85,6 @@ do \
     } \
 } while(0)
 
-
 #define add_timespec(sum, t1, t2) \
 do { \
     (sum).tv_sec = (t1).tv_sec + (t2).tv_sec; \
@@ -90,7 +92,12 @@ do { \
     normalize_timespec(sum); \
 } while(0)
 
-
+#define incr_timespec(t1, t2) \
+do { \
+        (t1).tv_sec += (t2).tv_sec; \
+        (t1).tv_nsec += (t2).tv_nsec; \
+        normalize_timespec(t1); \
+} while(0)
 
 // -------------------------------------------------------------------
 
@@ -100,7 +107,7 @@ do { \
 do { \
     if ((base).tv_nsec < (interval).tv_nsec) \
     { \
-        (diff).tv_sec = (base).tv_sec - (interval).tv_sec + 1; \
+        (diff).tv_sec = (base).tv_sec - (interval).tv_sec - 1; \
         (diff).tv_nsec = (base).tv_nsec + 1000000000 - (interval).tv_nsec; \
     } \
     else \
@@ -108,7 +115,7 @@ do { \
         (diff).tv_sec = (base).tv_sec - (interval).tv_sec; \
         (diff).tv_nsec = (base).tv_nsec - (interval).tv_nsec; \
     } \
-} while(0) 
+} while(0)
 
 
 // ---------------------------------------------------------
@@ -137,7 +144,7 @@ do { \
 // ---------------------------------------------------------
 
 #define timespec_to_msec(t1) \
-   ( ((t1).tv_sec % 2147482) * 1000 + (t1).tv_nsec/1000000 ) 
+   ( ((t1).tv_sec % 2147482) * 1000 + (t1).tv_nsec/1000000 )
 
 
 // ---------------------------------------------------------
@@ -186,7 +193,7 @@ do { \
 #define timespec_is_null(t1) ( (t1).tv_sec == 0 ) && ( (t1).tv_nsec == 0 )
 
 
-  
+
 /***************************************/
 /* T I M E S P E C   F U N C T I O N S */
 /***************************************/
@@ -195,7 +202,7 @@ do { \
 static inline fosa_abs_time_t fosa_abs_time_incr(fosa_abs_time_t base, fosa_rel_time_t interval)
 {
     fosa_abs_time_t result;
-    
+
     add_timespec(result, base, interval);
 
     return result;
@@ -237,7 +244,7 @@ static inline fosa_rel_time_t fosa_rel_time_add(fosa_rel_time_t relt1, fosa_rel_
 
     return result;
 }
-    
+
 
 // ---------------------------------------------------------
 
@@ -256,7 +263,7 @@ static inline fosa_rel_time_t fosa_rel_time_decr(fosa_rel_time_t total, fosa_rel
  * exact_long_multiply_smaller_10e5()
  *
  * Same as below but with operands smaller than 10000 which allows
- * to perform all component multiplications without an overflow risk. 
+ * to perform all component multiplications without an overflow risk.
  **/
 static inline struct timespec exact_long_multiply_smaller_10e5(long t, long k)
 {
@@ -299,10 +306,10 @@ static inline struct timespec exact_long_multiply_smaller_10e5(long t, long k)
     return result;
 }
 
-    
-// -------------------------------------------------------------    
 
-    
+// -------------------------------------------------------------
+
+
 
 /**
  * exact_long_multiply()
@@ -379,7 +386,7 @@ static inline struct timespec exact_long_multiply(long t, long k)
     {
         overflow_risk = true;
     }
-    
+
     if (! overflow_risk)
     {
         c0.tv_sec = 0;
@@ -394,8 +401,8 @@ static inline struct timespec exact_long_multiply(long t, long k)
 
     return result;
 }
-    
-// -------------------------------------------------------------    
+
+// -------------------------------------------------------------
 
 
 static inline fosa_rel_time_t fosa_rel_time_times_integer(fosa_rel_time_t time, long multiplier)
@@ -409,7 +416,7 @@ static inline fosa_rel_time_t fosa_rel_time_times_integer(fosa_rel_time_t time,
     intermediate = exact_long_multiply(time.tv_nsec, multiplier);
 
     add_timespec(result, result, intermediate);
-    
+
     return result;
 }
 
@@ -449,7 +456,7 @@ static inline fosa_rel_time_t fosa_rel_time_divided_by_integer(fosa_rel_time_t t
         enhacer *= 10;
         back_enhacer = 1000000000 / enhacer;
         next_numeral = (time.tv_nsec / back_enhacer) % 10;
-        
+
         // Note:  a possible overflow may happen here with large denominators
         if (reminder > 200000000)
         {
@@ -457,12 +464,12 @@ static inline fosa_rel_time_t fosa_rel_time_divided_by_integer(fosa_rel_time_t t
             abort();
         }
         next_dividend = reminder * 10 + next_numeral;
-        
+
         result.tv_nsec += (next_dividend / divider) * back_enhacer;
         reminder = next_dividend % divider;
     } while (back_enhacer > 1);
 
-    
+
     return result;
 }