From 7e971b3fa805c40d02ac3e996ab1d181f9584866 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 3 Jan 2021 16:58:00 +0100 Subject: Added h_sleep instead of usleep for better precision --- common/common.h | 6 +++--- common/helper.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/common.h b/common/common.h index 617db1a..d224264 100644 --- a/common/common.h +++ b/common/common.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 22:58:35 by cacharle #+# #+# */ -/* Updated: 2021/01/03 14:02:38 by cacharle ### ########.fr */ +/* Updated: 2021/01/03 16:34:25 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,14 +54,14 @@ bool parse_args(t_philo_args *args, int argc, char **argv); long int h_atou_strict(char *s); t_time h_time_now(void); -int h_err(int ret, const char *format, char *str); +void h_sleep(t_time sleep_time); /* ** io.c */ -void philo_put_set_initial_time(void); void philo_put( size_t id, t_philo_event event, t_time initial_time); +int h_err(int ret, const char *format, char *str); #endif diff --git a/common/helper.c b/common/helper.c index e1cc1e2..a9d0652 100644 --- a/common/helper.c +++ b/common/helper.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 23:22:49 by cacharle #+# #+# */ -/* Updated: 2021/01/02 12:07:49 by cacharle ### ########.fr */ +/* Updated: 2021/01/03 16:55:42 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,3 +48,12 @@ t_time h_time_now(void) gettimeofday(&tv, NULL); return (tv.tv_sec * 1000 + tv.tv_usec / 1000); } + +void h_sleep(t_time sleep_time) +{ + t_time start; + + start = h_time_now(); + while (h_time_now() - start < sleep_time) + usleep(500); +} -- cgit