From ec7a989cf45440e41d43e7fa2d2ce660fa499933 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 28 Jan 2025 13:21:34 +0100 Subject: Outsource init func to seperate file --- philo/src/main.c | 57 +------------------------------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) (limited to 'philo/src/main.c') diff --git a/philo/src/main.c b/philo/src/main.c index a43fe8d..ae0e54b 100644 --- a/philo/src/main.c +++ b/philo/src/main.c @@ -6,7 +6,7 @@ /* By: dkaiser id = id; - philo->is_alive = 1; - philo->times_must_eat = data->times_must_eat; - philo->data = data; - philo->last_time_eaten = ft_cur_time_in_ms(); -} - -int init_philos(t_philo **philos, t_phdata *data) -{ - int i; - int result; - - i = 0; - while (i < data->nbr_of_philos) - { - init_philo(&(*philos)[i], data, i + 1); - data->forks[i].owner = 0; - result = pthread_mutex_init(&(data->forks[i].mutex), NULL); - if (result != 0) - { - free(*philos); - free(data->forks); - return (result); - } - i++; - } - return (EXIT_SUCCESS); -} - -int init(t_philo **philos, t_phdata *data) -{ - int result; - - *philos = (t_philo *)malloc(sizeof(t_philo) * data->nbr_of_philos); - if (*philos == NULL) - return (ft_err(ERR_MALLOC)); - data->forks = (t_fork *)malloc(sizeof(t_fork) * data->nbr_of_philos); - if (data->forks == NULL) - { - free(*philos); - return (ft_err(ERR_MALLOC)); - } - result = pthread_mutex_init(&(data->pme_mutex), NULL); - if (result != 0) - { - free(*philos); - free(data->forks); - return (result); - } - result = init_philos(philos, data); - return (result); -} - int main(int argc, char *argv[]) { t_phdata data; -- cgit v1.2.3