1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
philosopher/philo/sleep.c
2024-07-23 18:11:44 +02:00

31 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sleep.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/23 17:15:24 by adjoly #+# #+# */
/* Updated: 2024/07/23 17:24:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
uint32_t time_to_ms(void)
{
struct timeval time;
gettimeofday(&time, NULL);
return (time.tv_sec * 1000 + time.tv_usec / 1000);
}
void sleep_phil(uint32_t sleep_time)
{
uint32_t t0;
t0 = time_to_ms() + sleep_time;
while (time_to_ms() < t0)
usleep(100);
}