aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-14 21:24:22 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-14 21:24:22 +0100
commitf6a960c09c9593af72ff6da2c3ed501e01a0f429 (patch)
tree783c452486c2528fe0df25d76f49d1d4f20c1d47 /common
parentadbe9cdb61e5d12299b8872b2ac27a48036bc95d (diff)
downloadphilosophers-f6a960c09c9593af72ff6da2c3ed501e01a0f429.tar.gz
philosophers-f6a960c09c9593af72ff6da2c3ed501e01a0f429.tar.bz2
philosophers-f6a960c09c9593af72ff6da2c3ed501e01a0f429.zip
philo one working (with what may be a hack)
Diffstat (limited to 'common')
-rw-r--r--common/common.c2
-rw-r--r--common/common.h6
-rw-r--r--common/helper.c14
-rw-r--r--common/philo.c2
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 */
/* */
/* ************************************************************************** */