From: faggioli Date: Thu, 27 Mar 2008 14:02:52 +0000 (+0000) Subject: move all the time related issues to FOSA absolute and relative data types. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/fosa.git/commitdiff_plain/b9253b6947ce55df2cbb88ce97b1c19b099d049d move all the time related issues to FOSA absolute and relative data types. git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1050 35b4ef3e-fd22-0410-ab77-dab3279adceb --- diff --git a/include/fosa_opaque_types.h b/include/fosa_opaque_types.h index 5f562ec..bf2ee76 100644 --- a/include/fosa_opaque_types.h +++ b/include/fosa_opaque_types.h @@ -239,9 +239,13 @@ typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE; #ifdef AQuoSA -#define __USE_UNIX98 +#include +#include +#define _XOPEN_SOURCE 500 +#define __USE_UNIX98 #include + #include #include #include diff --git a/src_aquosa/fosa_clocks_and_timers.c b/src_aquosa/fosa_clocks_and_timers.c index 9c7e293..756d0a8 100644 --- a/src_aquosa/fosa_clocks_and_timers.c +++ b/src_aquosa/fosa_clocks_and_timers.c @@ -58,18 +58,51 @@ // 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, ¤t_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; diff --git a/src_aquosa/fosa_mutexes_and_condvars.c b/src_aquosa/fosa_mutexes_and_condvars.c index c40e856..b940b98 100644 --- a/src_aquosa/fosa_mutexes_and_condvars.c +++ b/src_aquosa/fosa_mutexes_and_condvars.c @@ -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); } diff --git a/src_aquosa/fosa_threads_and_signals.c b/src_aquosa/fosa_threads_and_signals.c index 895a567..8b62f29 100644 --- a/src_aquosa/fosa_threads_and_signals.c +++ b/src_aquosa/fosa_threads_and_signals.c @@ -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 diff --git a/src_aquosa/fosa_time.c b/src_aquosa/fosa_time.c index 07c312d..fdbf95e 100644 --- a/src_aquosa/fosa_time.c +++ b/src_aquosa/fosa_time.c @@ -66,20 +66,6 @@ #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, ¤t_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, ¤t_time) != 0) return; }