]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blobdiff - frsh_time.h
Update transaction API
[frescor/frsh-include.git] / frsh_time.h
index a2eb6aee97aa8b728d9d8bfb98f70fb902a109d9..8ab5f63edf39ddaeabf3a0578b3f7d996bfeda38 100644 (file)
-/*
-** fosa_time.h
-** 
-** Made by Miguel marciano
-** Login   <miguel@namir.ctr.unican.es>
-** 
-** Started on  Mon Jan 21 20:01:04 2008 Miguel marciano
-** Last update Mon Jan 21 20:01:04 2008 Miguel marciano
-*/
+// -----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2009 FRESCOR consortium partners:
+//
+//    Universidad de Cantabria,              SPAIN
+//    University of York,                    UK
+//    Scuola Superiore Sant'Anna,            ITALY
+//    Kaiserslautern University,             GERMANY
+//    Univ. Politécnica  Valencia,           SPAIN
+//    Czech Technical University in Prague,  CZECH REPUBLIC
+//    ENEA                                   SWEDEN
+//    Thales Communication S.A.              FRANCE
+//    Visual Tools S.A.                      SPAIN
+//    Rapita Systems Ltd                     UK
+//    Evidence                               ITALY
+//
+//    See http://www.frescor.org for a link to partners' websites
+//
+//           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.
+//
+//
+//  based on previous work (FSF) done in the FIRST project
+//
+//   Copyright (C) 2005  Mälardalen University, SWEDEN
+//                       Scuola Superiore S.Anna, ITALY
+//                       Universidad de Cantabria, SPAIN
+//                       University of York, UK
+//
+//   FSF API web pages: http://marte.unican.es/fsf/docs
+//                      http://shark.sssup.it/contrib/first/docs/
+//
+//   This file is part of FRSH (FRescor ScHeduler)
+//
+//  FRSH 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.  FRSH 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 FRSH; see file
+//  COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+//  Cambridge, MA 02139, USA.
+//
+//  As a special exception, including FRSH header files in a file,
+//  instantiating FRSH generics or templates, or linking other files
+//  with FRSH 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.
+// -----------------------------------------------------------------------
+//frsh_spare_capacity_types.h
+//==============================================
+//  ******** *******    ********  **      **
+//  **///// /**////**  **//////  /**     /**
+//  **      /**   /** /**        /**     /**
+//  ******* /*******  /********* /**********
+//  **////  /**///**  ////////** /**//////**
+//  **      /**  //**        /** /**     /**
+//  **      /**   //** ********  /**     /**
+//  //       //     // ////////   //      // 
+//
+// FRSH(FRescor ScHeduler), pronounced "fresh"
+//==============================================
+
 #ifndef        FRSH_TIME_H_
 #define        FRSH_TIME_H_
 
+#include "frsh_core_types.h"
+#include "frsh_core.h"
+
+FRSH_CPP_BEGIN_DECLS
+
+/**
+ * @file frsh_time.h
+ **/
+
+
+/**
+ * \addtogroup core
+ **/
+/*@{*/
+
+/***********************
+ * Relational operations
+ ***********************/  
+
+/**
+ * frsh_abs_time_smaller()
+ *
+ * Check if an absolute time is smaller than another one.
+ **/
+static inline bool frsh_abs_time_smaller(frsh_abs_time_t t1, frsh_abs_time_t t2)
+{
+    return fosa_abs_time_smaller(t1, t2);
+}
+
+/**
+ * frsh_rel_time_smaller()
+ *
+ * Check if a relative interval is smaller than another one.
+ **/
+static inline bool frsh_rel_time_smaller(frsh_rel_time_t t1, frsh_rel_time_t t2)
+{
+    return fosa_rel_time_smaller(t1, t2);
+}
+
+/**
+ * frsh_abs_time_smaller_or_equal()
+ *
+ * Check if an absolute time is smaller than or equal to another one.
+ **/
+static inline bool frsh_abs_time_smaller_or_equal(frsh_abs_time_t t1, frsh_abs_time_t t2)
+{
+    return fosa_abs_time_smaller_or_equal(t1, t2);
+}
+
+/**
+ * frsh_rel_time_smaller_or_equal()
+ *
+ * Check if a relative interval is smaller than or equal to another one.
+ **/
+static inline bool frsh_rel_time_smaller_or_equal(frsh_rel_time_t t1, frsh_rel_time_t t2)
+{
+    return fosa_rel_time_smaller_or_equal(t1, t2);
+}
+
+
+/***********************
+ * Arithmetic operations
+ ***********************/  
+
+/**
+ * frsh_abs_time_incr()
+ *
+ * Add a relative interval to an absolute time.
+ */
+static inline frsh_abs_time_t frsh_abs_time_incr(frsh_abs_time_t base, frsh_rel_time_t interval)
+{
+    return fosa_abs_time_incr(base, interval);
+}
+
+/**
+ * frsh_rel_time_add()
+ *
+ * Add a relative interval to another one.
+ */
+static inline frsh_rel_time_t frsh_rel_time_add(frsh_rel_time_t t1, frsh_rel_time_t t2)
+{
+    return fosa_rel_time_add(t1, t2);
+}
+
+static inline frsh_rel_time_t frsh_rel_time_incr(frsh_rel_time_t t1, frsh_rel_time_t t2)
+{
+    return fosa_rel_time_add(t1, t2);
+}
+
+
+
+
+/**
+ * frsh_abs_time_decr
+ *
+ * Subtract a relative interval from an absolute time.
+ */
+static inline frsh_abs_time_t frsh_abs_time_decr(frsh_abs_time_t time, frsh_rel_time_t interval)
+{
+    return fosa_abs_time_decr(time, interval);
+}
+
+/**
+ * frsh_rel_time_decr()
+ *
+ * Subtract a relative interval from another one.
+ */
+static inline frsh_rel_time_t frsh_rel_time_decr(frsh_rel_time_t total, frsh_rel_time_t part)
+{
+    return fosa_rel_time_decr(total, part);
+}
+    
+
+/**
+ * frsh_abs_time_extract_interval()
+ * 
+ * Subtract two absolute times to get a relative interval.
+ */
+static inline frsh_rel_time_t frsh_abs_time_extract_interval(frsh_abs_time_t past, frsh_abs_time_t future)
+{
+    return fosa_abs_time_extract_interval(past, future);
+}
+
+
+static inline frsh_rel_time_t frsh_abs_time_subtract(frsh_abs_time_t past, frsh_abs_time_t future)
+{
+    return fosa_abs_time_extract_interval(past, future);
+}
+
+
+
+
+/**
+ * frsh_rel_time_times_integer()
+ * 
+ * Multiplies a relative time by an integer
+ */
+static inline frsh_rel_time_t frsh_rel_time_times_integer(frsh_rel_time_t time, long multiplier)
+{
+    return fosa_rel_time_times_integer(time, multiplier);
+}
+
+/**
+ * frsh_rel_time_times_integer()
+ * 
+ * Divides a relative time by an integer
+ **/
+static inline frsh_rel_time_t frsh_rel_time_divided_by_integer(frsh_rel_time_t time, long divider)
+{
+    return fosa_rel_time_divided_by_integer(time, divider);
+}
+
+
+/************************************
+ * Conversion to-from natural formats
+ * Note: Overflows may occur
+ ************************************/
+
+/**
+ * frsh_msec_to_rel_time()
+ *
+ * Convert an integer value of milliseconds into a relative time interval.
+ */
+static inline frsh_rel_time_t frsh_msec_to_rel_time(long msec)
+{
+    return fosa_msec_to_rel_time(msec);
+}
+
+/**
+ * frsh_rel_time_to_msec()
+ *
+ * Convert a relative interval into an integer number of milliseconds.
+ */
+static inline long frsh_rel_time_to_msec(frsh_rel_time_t interval)
+{
+    return fosa_rel_time_to_msec(interval);
+}
+
+/**
+ * frsh_msec_to_abs_time()
+ *
+ * Convert an integer value of milliseconds into an absolute time instant
+ */
+static inline frsh_abs_time_t frsh_msec_to_abs_time(long msec)
+{
+    return fosa_msec_to_abs_time(msec);
+}
+
+/**
+ * frsh_abs_time_to_msec()
+ *
+ * Convert an absolute instant into an integer number of milliseconds.
+ */
+static inline long frsh_abs_time_to_msec(frsh_abs_time_t instant)
+{
+    return fosa_abs_time_to_msec(instant);
+}
+
+/**
+ * frsh_usec_to_rel_time() 
+ *
+ * Convert an integer value of microseconds into an absolute instant.
+ */
+static inline frsh_rel_time_t frsh_usec_to_rel_time(long usec)
+{
+    return fosa_usec_to_rel_time(usec);
+}
+
+
+/**
+ * frsh_rel_time_to_usec() 
+ *
+ * Convert a relative interval into an integer number of microseconds.
+ */
+static inline long frsh_rel_time_to_usec(frsh_rel_time_t interval)
+{
+    return fosa_rel_time_to_usec(interval);
+}
+
+/**
+ * frsh_usec_to_abs_time() 
+ *
+ * Convert an integer value of microseconds into an absolute instant.
+ */
+static inline frsh_abs_time_t frsh_usec_to_abs_time(long usec)
+{
+    return fosa_usec_to_abs_time(usec);
+}
+
+
+/**
+ * frsh_abs_time_to_usec() 
+ *
+ * Convert a relative interval into an integer number of microseconds.
+ */
+static inline long frsh_abs_time_to_usec(frsh_abs_time_t interval)
+{
+    return fosa_abs_time_to_usec(interval);
+}
+
+/**
+ * frsh_nsec_to_rel_time() 
+ *
+ * Convert an integer value of microseconds into an absolute instant.
+ */
+static inline frsh_rel_time_t frsh_nsec_to_rel_time(long nsec)
+{
+    return fosa_nsec_to_rel_time(nsec);
+}
+
+
+/**
+ * frsh_rel_time_to_nsec() 
+ *
+ * Convert a relative interval into an integer number of microseconds.
+ */
+static inline long frsh_rel_time_to_nsec(frsh_rel_time_t interval)
+{
+    return fosa_rel_time_to_nsec(interval);
+}
+
+/**
+ * frsh_nsec_to_abs_time() 
+ *
+ * Convert an integer value of microseconds into an absolute instant.
+ */
+static inline frsh_abs_time_t frsh_nsec_to_abs_time(long nsec)
+{
+    return fosa_nsec_to_abs_time(nsec);
+}
+
+
+/**
+ * frsh_abs_time_to_nsec() 
+ *
+ * Convert a relative interval into an integer number of microseconds.
+ */
+static inline long frsh_abs_time_to_nsec(frsh_abs_time_t interval)
+{
+    return fosa_abs_time_to_nsec(interval);
+}
+
+/******************************************
+ * Conversion to-from POSIX timespec format
+ ******************************************/
+
+/**
+ * frsh_timespec_to_rel_time()
+ * 
+ * Convert a POSIX timespec value into a relative time interval.
+ */
+static inline frsh_rel_time_t frsh_timespec_to_rel_time(struct timespec interval)
+{
+    return fosa_timespec_to_rel_time(interval);
+}
+
+/**
+ * frsh_rel_time_to_timespec() 
+ *
+ * Convert a relative interval into a POSIX timespec value.
+ */
+static inline struct timespec frsh_rel_time_to_timespec(frsh_rel_time_t interval)
+{
+    return fosa_rel_time_to_timespec(interval);
+}
+
+/**
+ * frsh_timespec_to_abs_time()
+ * 
+ * Convert a POSIX timespec value into an absolute time.
+ */
+static inline frsh_abs_time_t frsh_timespec_to_abs_time(struct timespec time)
+{
+    return fosa_timespec_to_abs_time(time);
+}
+
+/**
+ * frsh_abs_time_to_timespec()
+ * 
+ * Convert an absolute time into a POSIX timespec value.
+ */
+static inline struct timespec frsh_abs_time_to_timespec(frsh_abs_time_t time)
+{
+    return fosa_abs_time_to_timespec(time);
+}
+
+
 /**
  * frsh_eat()
  *
- * Eat some time using system clock facilities
+ * Keep the thread busy executing for a given period of time.
  **/
-static void inline frsh_eat(const struct timespec *cpu_time)
+static inline void  frsh_eat(frsh_rel_time_t *cpu_time)
 {
     fosa_eat(cpu_time);
 }
 
+/*@}*/
+
+FRSH_CPP_END_DECLS
 
 #endif             /* !FOSA_TIME_H_ */