diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/common.c | 2 | ||||
| -rw-r--r-- | common/common.h | 6 | ||||
| -rw-r--r-- | common/helper.c | 14 | ||||
| -rw-r--r-- | common/philo.c | 2 |
4 files changed, 18 insertions, 6 deletions
diff --git a/common/common.c b/common/common.c index 0ec7f80..381256b 100644 --- a/common/common.c +++ b/common/common.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 23:12:55 by cacharle #+# #+# */ -/* Updated: 2020/02/14 01:32:37 by cacharle ### ########.fr */ +/* Updated: 2020/02/14 19:42:18 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/common/common.h b/common/common.h index e314960..a838750 100644 --- a/common/common.h +++ b/common/common.h @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 22:58:35 by cacharle #+# #+# */ -/* Updated: 2020/02/14 00:35:30 by cacharle ### ########.fr */ +/* Updated: 2020/02/14 20:45:33 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,6 +48,9 @@ typedef struct t_time timeout_eat; t_time timeout_sleep; int meal_num; + t_bool all_alive; + pthread_mutex_t mutex_stdout; + pthread_mutex_t mutex_all_alive; } t_philo_args; typedef void (*t_philo_routine)(void *arg); @@ -79,5 +82,6 @@ void h_putchar(char c); void h_putstr(char *s); void *h_calloc(int count, int size); t_time h_timeval_to_time(struct timeval *tp); +t_time h_time_now(void); #endif diff --git a/common/helper.c b/common/helper.c index afdb7f3..2826ceb 100644 --- a/common/helper.c +++ b/common/helper.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 23:22:49 by cacharle #+# #+# */ -/* Updated: 2020/02/14 01:37:31 by cacharle ### ########.fr */ +/* Updated: 2020/02/14 21:07:54 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,7 +74,15 @@ t_time h_timeval_to_time(struct timeval *tp) { t_time t; - t = tp->tv_sec * 1000; - t += tp->tv_usec / 1000; + t = tp->tv_sec * 1000 + tp->tv_usec / 1000; return (t); } + +t_time h_time_now(void) +{ + struct timeval tv; + + if (gettimeofday(&tv, NULL) == -1) + return (-1); + return (h_timeval_to_time(&tv)); +} diff --git a/common/philo.c b/common/philo.c index dfc9278..d342802 100644 --- a/common/philo.c +++ b/common/philo.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/09 01:54:53 by cacharle #+# #+# */ -/* Updated: 2020/02/14 00:29:17 by cacharle ### ########.fr */ +/* Updated: 2020/02/14 21:21:02 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ |
