From 47beba686ff9d2aab63738fba7176a5235703d05 Mon Sep 17 00:00:00 2001 From: yctct Date: Sun, 13 Sep 2026 18:58:14 +0200 Subject: Add all files, first commit --- src/time.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/time.c (limited to 'src/time.c') diff --git a/src/time.c b/src/time.c new file mode 100644 index 0000000..76f3528 --- /dev/null +++ b/src/time.c @@ -0,0 +1,29 @@ +#include "codexion.h" +# include // for getimeofday() + +long time_ms(void) +{ + long current_time_ms; + struct timeval current_t; + + gettimeofday(¤t_t, NULL); + current_time_ms = current_t.tv_sec * 1000L + current_t.tv_usec / 1000L; + return (current_time_ms); +} + +void start_timer(t_sim *sim) +{ + sim->start_time = time_ms(); +} + +int get_rel_time(t_sim *sim) +{ + int current_rel_time; + long start_time; + + (void)pthread_mutex_lock(&sim->mutex_start_time); + start_time = sim->start_time; + (void)pthread_mutex_unlock(&sim->mutex_start_time); + current_rel_time = time_ms() - start_time; + return (current_rel_time); +} -- cgit v1.2.3