]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_aquosa/fosa_time.c
Bugfixes and restyling.
[frescor/fosa.git] / src_aquosa / fosa_time.c
index 07c312d88f6541480accd2498308fceb2ab00fce..571ccce8ce787512ab4d7a4aecbb11f21b8e08a0 100644 (file)
 //================================================
 
 #include "fosa_time.h"
+#include "fosa_clocks_and_timers.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()
  *
@@ -93,18 +80,15 @@ void inline fosa_eat(const struct timespec *cpu_time)
        struct timespec current_time, time_to_go;
 
        self = fosa_thread_self();
-       if (self.linux_pid == self.linux_tid)
-               error = clock_getcpuclockid(self.linux_pid, &clock_id);
-       else
-               error = pthread_getcpuclockid(self.pthread_id, &clock_id);
-       if (error != 0)
+       error = fosa_thread_get_cputime_clock(self, &clock_id);
+       if (!error)
                return;
 
        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;
 }