summaryrefslogtreecommitdiff
path: root/src/time.c
diff options
context:
space:
mode:
authoryctct <yctct@yctct.com>2026-09-13 18:58:14 +0200
committeryctct <yctct@yctct.com>2026-09-13 18:58:14 +0200
commit47beba686ff9d2aab63738fba7176a5235703d05 (patch)
treef839ed36a9e9d4476fcdc59379b17903abfa35c8 /src/time.c
Add all files, first commit
Diffstat (limited to 'src/time.c')
-rw-r--r--src/time.c29
1 files changed, 29 insertions, 0 deletions
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 <sys/time.h> // for getimeofday()
+
+long time_ms(void)
+{
+ long current_time_ms;
+ struct timeval current_t;
+
+ gettimeofday(&current_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);
+}