summaryrefslogtreecommitdiff
path: root/src/time.c
blob: 76f35281c1af91ee975da7f5d0a9f6e1bee1ed89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
}