philosophers/philo/philo.h
2023-05-20 09:08:51 +02:00

77 lines
2.3 KiB
C

/* ************************************************************************** */
/* */
/* .--. _ */
/* philo.h |o_o || | */
/* |:_/ || |_ _ ___ __ */
/* By: houtworm <codam@houtworm.net> // \ \ __| | | \ \/ / */
/* (| | )|_| |_| |> < */
/* Created: 2023/03/11 07:19:18 by houtworm /'\_ _/`\__|\__,_/_/\_\ */
/* Updated: 2023/05/20 08:07:24 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 *drdead;
pthread_mutex_t *drdone;
pthread_mutex_t *drcycle;
pthread_mutex_t *drlastfood;
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];
t_philo philo[512];
pthread_mutex_t drdead;
pthread_mutex_t drdone;
pthread_mutex_t drcycle;
pthread_mutex_t drlastfood;
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 i);
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);
void ft_aliveprint(t_philo *ps, char *str);
#endif