]> rtime.felk.cvut.cz Git - frescor/fosa.git/commitdiff
move all the time related issues to FOSA absolute and relative data types.
authorfaggioli <faggioli@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Thu, 27 Mar 2008 14:02:52 +0000 (14:02 +0000)
committerfaggioli <faggioli@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Thu, 27 Mar 2008 14:02:52 +0000 (14:02 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1050 35b4ef3e-fd22-0410-ab77-dab3279adceb

include/fosa_opaque_types.h
src_aquosa/fosa_clocks_and_timers.c
src_aquosa/fosa_mutexes_and_condvars.c
src_aquosa/fosa_threads_and_signals.c
src_aquosa/fosa_time.c

index 5f562ec70e2ad3cb56572212cd10a4453070a9dc..bf2ee76cb093b28bb7ef62a8c401837e3d85a795 100644 (file)
@@ -239,9 +239,13 @@ typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
 
 #ifdef AQuoSA
 
-#define __USE_UNIX98
+#include <unistd.h>
+#include <linux/unistd.h>
 
+#define _XOPEN_SOURCE 500
+#define __USE_UNIX98
 #include <pthread.h>
+
 #include <signal.h>
 #include <errno.h>
 #include <time.h>
index 9c7e2930cda6e9cf384f21b41baad35610b746da..756d0a89c4211f7e4178359b499f002080f809d0 100644 (file)
 // FOSA(Frescor Operating System Adaptation layer)
 //================================================
 
+#include "fosa_time.h"
 #include "fosa_clocks_and_timers.h"
 
 /*************************
  * Timing: Clocks
  *************************/
 
+/**
+ * fosa_get_time()
+ *
+ * Get the time from a clock
+ *
+ * This function sets the variable pointed to by current_time to the
+ * current value of the clock specified by clockid, which may be the
+ * FOSA_CLOCK_REALTIME constant or a value obtained with
+ * fosa_get_cputime_clock()
+ *
+ * Returns 0 if successful; otherwise it returns an error code:
+ *     EINVAL: the value of clockid is invalid
+ **/
 int fosa_clock_get_time(fosa_clock_id_t clockid,
-                       struct timespec *current_time)
+                       fosa_abs_time_t *current_time)
 {
-       return clock_gettime(clockid, current_time);
+       int error;
+       struct timespec current_time_tspec;
+
+       if ((error = clock_gettime(clockid, &current_time_tspec)) != 0)
+               return error;
+
+       *current_time = fosa_timespec_to_abs_time(current_time_tspec);
+
+       return 0;
 }
 
+/**
+ * fosa_get_cputime_clock()
+ *
+ * Get the identifier of a cpu-time clock
+ *
+ * This function stores in the variable pointed to by clockid the
+ * identifier of a cpu-time clock for the thread specified by tid.
+ *
+ * Returns 0 if successful; otherwise it returns an error code:
+ *    EINVAL: the value of tid is invalid
+ **/
 int fosa_thread_get_cputime_clock(fosa_thread_id_t tid,
                                  fosa_clock_id_t *clockid)
 {
@@ -154,16 +187,16 @@ int fosa_timer_create(fosa_clock_id_t clockid,
        return ENOSYS;
 }
 
- /**
 * Delete a timer
 *
 * The function deletes the timer specified by timerid, which becomes
 * unusable. If the timer was armed, it is automatically disarmed before
 * deletion.
 *
 * Returns 0 if successful; otherwise it returns an error code:
 *     EINVAL: the value of timerid is not valid
 **/
+/**
+ * Delete a timer
+ *
+ * The function deletes the timer specified by timerid, which becomes
+ * unusable. If the timer was armed, it is automatically disarmed before
+ * deletion.
+ *
+ * Returns 0 if successful; otherwise it returns an error code:
+ *     EINVAL: the value of timerid is not valid
+ **/
 int fosa_timer_delete(fosa_timer_id_t  timerid)
 {
        return timer_delete(timerid);
@@ -196,12 +229,12 @@ int fosa_timer_delete(fosa_timer_id_t  timerid)
  **/
 int fosa_timer_arm (fosa_timer_id_t timerid,
                    bool abstime,
-                   const struct timespec *value)
+                   const fosa_abs_time_t *value)
 {
        struct itimerspec when;
 
        /* non-periodic one shot timer configuration */
-       when.it_value = *value;
+       when.it_value = fosa_abs_time_to_timespec(*value);
        when.it_interval.tv_sec = 0;
        when.it_interval.tv_nsec = 0;
 
@@ -226,7 +259,7 @@ int fosa_timer_arm (fosa_timer_id_t timerid,
  *    EINVAL: the value of timerid or value is invalid
  **/
 int fosa_timer_get_remaining_time(fosa_timer_id_t timerid,
-                                 struct timespec *remaining_time)
+                                 fosa_rel_time_t *remaining_time)
 {
        int error;
        struct itimerspec time;
@@ -235,7 +268,7 @@ int fosa_timer_get_remaining_time(fosa_timer_id_t timerid,
                if ((error = timer_gettime(timerid, &time)) == -1)
                        return error;
 
-               *remaining_time = time.it_value;
+               *remaining_time = fosa_timespec_to_rel_time(time.it_value);
        } else
                return EINVAL;
 
@@ -268,7 +301,7 @@ int fosa_timer_disarm(fosa_timer_id_t timerid,
                if ((error = timer_gettime(timerid, &time)) == -1)
                        return error;
 
-               *remaining_time = time.it_value;
+               *remaining_time = fosa_timespec_to_rel_time(time.it_value);
        }
 
        time.it_value.tv_sec = 0;
index c40e85633f3218728d10677b223c99b203b68311..b940b988a11f5386d8af3ad36198d028b4441614 100644 (file)
@@ -58,6 +58,7 @@
 // FOSA(Frescor Operating System Adaptation layer)
 //================================================
 
+#include "fosa_time.h"
 #include "fosa_mutexes_and_condvars.h"
 
 /*******************************************************
@@ -310,7 +311,11 @@ int fosa_cond_wait(fosa_cond_t *cond, fosa_mutex_t *mutex)
  **/
 int fosa_cond_timedwait(fosa_cond_t *cond,
        fosa_mutex_t *mutex,
-       const struct timespec *abstime)
+       const fosa_abs_time_t *abstime)
 {
-       return pthread_cond_timedwait(cond, mutex, abstime);
+       struct timespec abstime_tspec;
+
+       abstime_tspec = fosa_abs_time_to_timespec(*abstime);
+
+       return pthread_cond_timedwait(cond, mutex, &abstime_tspec);
 }
index 895a567f20e4390ac59c28ea7ec9de26d1676231..8b62f294375ae9136e2dfe4059283b902f4fe40a 100644 (file)
@@ -57,8 +57,9 @@
 // FOSA(Frescor Operating System Adaptation layer)
 //================================================
 
-#include "fosa_threads_and_signals.h"
+#include "fosa_time.h"
 #include "fosa_configuration_parameters.h"
+#include "fosa_threads_and_signals.h"
 
 /*************************
  * Storage of thread-specific keys
index 07c312d88f6541480accd2498308fceb2ab00fce..fdbf95e17f5b2d2c204156ec6c80700c7d9ddad5 100644 (file)
 #include "fosa_time.h"
 #include "fosa_threads_and_signals.h"
 
-#define timespec_add(t1, t2, sum)                      \
- do {                                                  \
-   (sum)->tv_sec = (t1).tv_sec + (t2).tv_sec;          \
-   (sum)->tv_nsec = (t1).tv_nsec + (t2).tv_nsec;       \
-   if ((sum)->tv_nsec >= 1000000000) {                 \
-     (sum)->tv_sec++;                                  \
-     (sum)->tv_nsec -= 1000000000;                     \
-   }                                                   \
- } while (0)
-
-#define timespec_smaller(t1, t2)                               \
- ( (t1).tv_sec < (t2).tv_sec || ((t1).tv_sec == (t2).tv_sec && \
-   (t1).tv_nsec < (t2).tv_nsec) )
-
 /**
  * fosa_eat()
  *
@@ -103,8 +89,8 @@ void inline fosa_eat(const struct timespec *cpu_time)
        if (clock_gettime(clock_id, &current_time) != 0)
                        return;
 
-       timespec_add(current_time, *cpu_time, &time_to_go);
-       while (timespec_smaller(current_time, time_to_go))
+       time_to_go = fosa_abs_time_incr(current_time, *cpu_time);
+       while (fosa_abs_time_smaller_or_equal(current_time, time_to_go))
                if (clock_gettime(clock_id, &current_time) != 0)
                        return;
 }