philosophers/philo_bonus/philo.h
Danny Jonker 4580f4d963 firsttry
2023-05-18 17:02:05 +02:00

79 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/14 08:55:03 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#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 <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 *target;
sem_t *done;
sem_t *dead;
sem_t *hold;
sem_t *print;
} 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;
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 ft_cyclecounter(t_strct *strct);
int ft_waitingfordeath(t_strct *strct);
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