2023-04-27 08:05:14 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* philos.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/04/27 11:30:32 by cchauvet #+# #+# */
|
|
|
|
/* Updated: 2023/04/27 11:30:33 by cchauvet ### ########.fr */
|
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2023-04-13 09:00:39 -04:00
|
|
|
#include "./philo.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
int philos_init(t_data *data)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < data->nb_philos)
|
|
|
|
{
|
|
|
|
data->philos[i] = philo_init(data);
|
|
|
|
if (data->philos[i] == NULL)
|
|
|
|
{
|
|
|
|
while (i > 0)
|
|
|
|
{
|
|
|
|
philo_destroyer(data->philos[i]);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void philos_destroyer(t_data *data)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < data->nb_philos)
|
|
|
|
{
|
|
|
|
philo_destroyer(data->philos[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
free(data->philos);
|
|
|
|
}
|