// 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)
{
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);
**/
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;
* 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;
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;
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;
// FOSA(Frescor Operating System Adaptation layer)
//================================================
+#include "fosa_time.h"
#include "fosa_mutexes_and_condvars.h"
/*******************************************************
**/
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);
}
#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()
*
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;
}