From 42360f381cebd6376c261b16038a7f12971f925e Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Wed, 30 Sep 2020 08:18:29 +0200 Subject: Added 'has taken fork' log, Refactoring philo_one to work with new common lib --- philo_one/src/main.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'philo_one/src/main.c') diff --git a/philo_one/src/main.c b/philo_one/src/main.c index 511fdbe..53c1c56 100644 --- a/philo_one/src/main.c +++ b/philo_one/src/main.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/24 05:53:02 by cacharle #+# #+# */ -/* Updated: 2020/09/29 13:26:07 by cacharle ### ########.fr */ +/* Updated: 2020/09/30 08:06:03 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,35 +14,33 @@ int main(int argc, char **argv) { - t_philo_conf philo_args; + t_philo_conf conf; t_philo *philos; pthread_mutex_t *forks; t_routine_arg *routine_args; - if (!parse_args(&philo_args, argc, argv)) + if (!parse_args((t_philo_args*)&conf, argc, argv)) return (1); - if (philo_args.philo_num == 0) + if (conf.philo_num == 0) return (0); - if ((forks = forks_new(philo_args.philo_num)) == NULL) + if ((forks = forks_new(conf.philo_num)) == NULL) return (1); - if ((philos = philos_new(philo_args.philo_num)) == NULL) + if ((philos = philos_new(conf.philo_num)) == NULL) return (1); - if ((routine_args = forks_dispatch(philos, forks, &philo_args)) == NULL) + if ((routine_args = forks_dispatch(philos, forks, &conf)) == NULL) return (1); - philo_args.all_alive = true; - pthread_mutex_init(&philo_args.mutex_all_alive, NULL); - pthread_mutex_init(&philo_args.mutex_stdout, NULL); - if (!philos_start(philos, routine_args, philo_args.philo_num)) + conf.all_alive = true; + pthread_mutex_init(&conf.mutex_all_alive, NULL); + pthread_mutex_init(&conf.mutex_stdout, NULL); + if (!philos_start(philos, routine_args, conf.philo_num)) return (1); - /* pthread_mutex_lock(philo_args.mutex_all_alive); */ - /* pthread_mutex_lock(philo_args.mutex_all_alive); */ - while (philo_args.all_alive) + while (conf.all_alive) ; - philos_join(philos, philo_args.philo_num); - pthread_mutex_destroy(&philo_args.mutex_stdout); - pthread_mutex_destroy(&philo_args.mutex_all_alive); + philos_detach(philos, conf.philo_num); + pthread_mutex_destroy(&conf.mutex_stdout); + pthread_mutex_destroy(&conf.mutex_all_alive); free(routine_args); free(philos); - forks_destroy(forks, philo_args.philo_num); + forks_destroy(forks, conf.philo_num); return (0); } -- cgit