71 lines
2.1 KiB
C
71 lines
2.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* .--. _ */
|
|
/* philo.h |o_o || | */
|
|
/* |:_/ || |_ _ ___ __ */
|
|
/* By: houtworm <codam@houtworm.net> // \ \ __| | | \ \/ / */
|
|
/* (| | )|_| |_| |> < */
|
|
/* Created: 2023/03/11 07:19:18 by houtworm /'\_ _/`\__|\__,_/_/\_\ */
|
|
/* Updated: 2023/05/14 06:08:32 by djonker \___)=(___/ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef PHILO_H
|
|
# define PHILO_H
|
|
|
|
# include <unistd.h>
|
|
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
# include <pthread.h>
|
|
# include <sys/time.h>
|
|
|
|
typedef struct s_philo
|
|
{
|
|
int id;
|
|
int cycles;
|
|
pthread_mutex_t *forks;
|
|
pthread_mutex_t *datarace;
|
|
int *philos;
|
|
int lfork;
|
|
int rfork;
|
|
long long lastfood;
|
|
long long *dietime;
|
|
long long *eattime;
|
|
long long *sleeptime;
|
|
long long *strtt;
|
|
int *target;
|
|
int *done;
|
|
int *dead;
|
|
pthread_t thrd;
|
|
} t_philo;
|
|
|
|
typedef struct s_strct
|
|
{
|
|
pthread_mutex_t forks[512];
|
|
pthread_mutex_t datarace[3];
|
|
t_philo philo[512];
|
|
int philos;
|
|
long long dietime;
|
|
long long eattime;
|
|
long long sleeptime;
|
|
long long strtt;
|
|
int target;
|
|
int done;
|
|
int dead;
|
|
char *error;
|
|
} t_strct;
|
|
|
|
t_strct *ft_parseandvalidateinput(int argc, char **argv);
|
|
int ft_initstructandmutex(t_strct *strct);
|
|
int ft_startcycle(t_strct *strct);
|
|
void *ft_cycle(void *pointer);
|
|
int ft_liveordie(t_strct *strct, int i);
|
|
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);
|
|
int ft_alivecheck(t_philo *ps);
|
|
|
|
#endif
|