#include "frsh_fosa.h"
#include <pthread.h>
#include <stdio.h>
+#include <time.h>
+
+#include <timespec_operations.h> /* for incr_timespec */
#include <misc/error_checks.h>
{
return pthread_attr_getstacksize(attr,stacksize);
}
+
+
+/**
+ * frsh_eat()
+ *
+ * Eat some time using system clock facilities
+ **/
+#ifdef VIRTUAL_TIME
+ #include <fosa_vt.h>
+#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
+}