84 lines
2.4 KiB
C
84 lines
2.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* .--. _ */
|
|
/* philo.h :+: :+: :+: */
|
|
/* |:_/ || |_ _ ___ __ */
|
|
/* By: houtworm <codam@houtworm.net> // \ \ __| | | \ \/ / */
|
|
/* (| | )|_| |_| |> < */
|
|
/* Created: 2023/03/11 07:19:18 by houtworm /'\_ _/`\__|\__,_/_/\_\ */
|
|
/* Updated: 2023/05/22 07:37:35 by houtworm ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef PHILO_H
|
|
# define PHILO_H
|
|
|
|
# include <unistd.h>
|
|
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
# include <fcntl.h>
|
|
# include <signal.h>
|
|
# include <semaphore.h>
|
|
# include <pthread.h>
|
|
# include <sys/time.h>
|
|
# include <sys/wait.h>
|
|
|
|
typedef struct s_philo
|
|
{
|
|
int id;
|
|
int cycles;
|
|
sem_t *forks;
|
|
int *philos;
|
|
int *pid;
|
|
int lfork;
|
|
int rfork;
|
|
long long lastfood;
|
|
long long *dietime;
|
|
long long *eattime;
|
|
long long *sleeptime;
|
|
long long *strtt;
|
|
int *alive;
|
|
int *target;
|
|
sem_t *done;
|
|
sem_t *dead;
|
|
sem_t *hold;
|
|
sem_t *print;
|
|
pthread_t thrd;
|
|
} t_philo;
|
|
|
|
typedef struct s_strct
|
|
{
|
|
sem_t *forks;
|
|
t_philo philo[512];
|
|
int pid[512];
|
|
int philos;
|
|
long long dietime;
|
|
long long eattime;
|
|
long long sleeptime;
|
|
long long strtt;
|
|
int target;
|
|
int alive;
|
|
sem_t *done;
|
|
sem_t *dead;
|
|
sem_t *hold;
|
|
sem_t *print;
|
|
char *error;
|
|
} t_strct;
|
|
|
|
t_strct *ft_parseandvalidateinput(int argc, char **argv);
|
|
int ft_initstructandmutex(t_strct *strct, int i);
|
|
int ft_startcycle(t_strct *strct);
|
|
void ft_cycle(void *pointer);
|
|
int ft_releasetheminds(t_strct *strct, int m);
|
|
int ft_cyclecounter(t_strct *strct);
|
|
int ft_waitingfordeath(t_strct *strct);
|
|
void *ft_alive(void *pointer);
|
|
int ft_cleanup(t_strct *strct);
|
|
long long ft_time(void);
|
|
int philo_atoi(char *str);
|
|
int ft_printreturn(char *reason, int code);
|
|
int ft_charactercheck(int argc, char **argv);
|
|
void ft_safeprint(t_philo *ps, char *str);
|
|
|
|
#endif
|