aboutsummaryrefslogtreecommitdiff
path: root/philo_one/main.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-10 00:34:47 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-10 01:30:53 +0100
commit1a7c6c5a0ed9a5aae1fe45c3af335c120c2dc642 (patch)
tree965aa21be5411d2a9e1156013efc1980bca29f90 /philo_one/main.c
parentdfbafce6506fe5c47b0e60289a9d4629e502c9ac (diff)
downloadphilosophers-1a7c6c5a0ed9a5aae1fe45c3af335c120c2dc642.tar.gz
philosophers-1a7c6c5a0ed9a5aae1fe45c3af335c120c2dc642.tar.bz2
philosophers-1a7c6c5a0ed9a5aae1fe45c3af335c120c2dc642.zip
WIP: philo one
Diffstat (limited to 'philo_one/main.c')
-rw-r--r--philo_one/main.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/philo_one/main.c b/philo_one/main.c
index 3bb1181..ef00a0b 100644
--- a/philo_one/main.c
+++ b/philo_one/main.c
@@ -6,21 +6,48 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/24 05:53:02 by cacharle #+# #+# */
-/* Updated: 2019/11/24 06:35:10 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 01:29:50 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo_one.h"
+
int main(int argc, char **argv)
{
- if (argc != 5 || argc != 6)
+ t_philo_args philo_args;
+ t_philo *philos;
+ t_fork *forks;
+ t_routine_arg *routine_args;
+
+ if (!parse_args(&philo_args, argc, argv))
+ return (1);
+ if ((forks = forks_new(philo_args.philo_num - 1)) == NULL)
+ return (1);
+ if ((philos = philos_new(philo_args.philo_num)) == NULL)
+ {
+ free(forks);
+ return (1);
+ }
+ if ((routine_args = forks_dispatch(philos, forks, &philo_args)) == NULL)
+ {
+ free(forks);
+ free(philos);
+ return (1);
+ }
+ if (!philos_start(philos, routine_args, philo_args.philo_num))
+ {
+ free(philos);
+ free(forks);
+ free(routine_args);
return (1);
- int philo_nb = ft_atoi(argv[1]);
- int death_timer = ft_atoi(argv[2]);
- int eat_timer = ft_atoi(argv[3]);
- int sleep_timer = ft_atoi(argv[4]);
- if (argc == 6)
- int eat_nb = ft_atoi(argv[5]);
+ }
+ while (TRUE)
+ if (philos_starved(philos, philo_args.philo_num))
+ break;
+ philos_join(philos, philo_args.philo_num);
+ free(philos);
+ free(forks);
+ free(routine_args);
return (0);
}