71 lines
1.1 KiB
C
71 lines
1.1 KiB
C
#include "../includes/philo_header.h"
|
|
|
|
t_all *structalloc_and_bzero(void)
|
|
{
|
|
t_all *all;
|
|
|
|
all = ft_calloc(sizeof(t_all), 1);
|
|
all->number_of_philosophers = -1;
|
|
all->time_to_die = -1;
|
|
all->time_to_eat = -1;
|
|
all->time_to_sleep = -1;
|
|
all->number_of_times_each_philosopher_must_eat = -1;
|
|
return(all);
|
|
}
|
|
|
|
int return_big(int a, int b)
|
|
{
|
|
if (a > b)
|
|
{
|
|
return (a);
|
|
}
|
|
return (b);
|
|
}
|
|
|
|
int return_less(int a, int b)
|
|
{
|
|
if (a < b)
|
|
{
|
|
return (a);
|
|
}
|
|
return (b);
|
|
}
|
|
|
|
void ft_exit(t_all *all)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
all->smert = 42;
|
|
ft_msleep(200);
|
|
while (i <= all->number_of_philosophers)
|
|
{
|
|
// pthread_mutex_destroy(&all->data_philo->philors[i].eat_mutex);
|
|
//pthread_mutex_destroy(&all->data_philo->mutex[i]); // TODO fix this
|
|
i++;
|
|
}
|
|
i = 0;
|
|
while (i < all->number_of_philosophers)
|
|
{
|
|
free(&all->data_philo->philors[i]);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
char *sem_set_name(char *str, int i)
|
|
{
|
|
char *temp_nbr;
|
|
char *returnstr;
|
|
|
|
temp_nbr = ft_itoa(i);
|
|
returnstr = ft_strjoin(str, temp_nbr);
|
|
free(temp_nbr);
|
|
return(returnstr);
|
|
}
|
|
|
|
sem_t *reopen_sem(const char *name, int value)
|
|
{
|
|
sem_unlink(name);
|
|
return (sem_open(name, O_RDWR | O_CREAT, S_IRWXU, value));
|
|
}
|