From 2dee1db328f4eb8183de3d78c673070e4a56e050 Mon Sep 17 00:00:00 2001 From: telleriam Date: Thu, 15 Nov 2007 16:30:44 +0000 Subject: [PATCH] Creation of frsh_eat() to be used in FOSA tests git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@853 35b4ef3e-fd22-0410-ab77-dab3279adceb --- src_marte/frsh_fosa.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src_marte/frsh_fosa.c b/src_marte/frsh_fosa.c index 094f26c..66c64e9 100644 --- a/src_marte/frsh_fosa.c +++ b/src_marte/frsh_fosa.c @@ -66,6 +66,9 @@ #include "frsh_fosa.h" #include #include +#include + +#include /* for incr_timespec */ #include @@ -160,3 +163,37 @@ int frsh_thread_attr_get_stacksize { return pthread_attr_getstacksize(attr,stacksize); } + + +/** + * frsh_eat() + * + * Eat some time using system clock facilities + **/ +#ifdef VIRTUAL_TIME + #include +#endif + +void inline frsh_eat(const struct timespec *cpu_time) +{ +#ifdef VIRTUAL_TIME + vt_time_t vt_clock; + timespec_2_vtime(cpu_time, vt_clock); + vt_use_time((unsigned long long)vt_clock); +#else + int err; + clockid_t clock_id; + struct timespec current_time, time_to_go; + + // NOTE: there should be a constant for the cpu_clock_id of the caller + // to avoid calling 'fosa_thread_get_cputime_clock' + err = pthread_getcpuclockid(pthread_self(), &clock_id); + + err = clock_gettime(clock_id, ¤t_time); + add_timespec(&time_to_go, ¤t_time, cpu_time); + + while (smaller_timespec(¤t_time, &time_to_go)) { + err = clock_gettime(clock_id, ¤t_time); + } +#endif +} -- 2.39.2