philosophers/philo_bonus/philo.h

84 lines
2.4 KiB
C
Raw Normal View History

2023-05-18 17:02:05 +02:00
/* ************************************************************************** */
/* */
/* .--. _ */
2023-05-22 08:14:22 +02:00
/* philo.h :+: :+: :+: */
2023-05-18 17:02:05 +02:00
/* |:_/ || |_ _ ___ __ */
/* By: houtworm <codam@houtworm.net> // \ \ __| | | \ \/ / */
/* (| | )|_| |_| |> < */
/* Created: 2023/03/11 07:19:18 by houtworm /'\_ _/`\__|\__,_/_/\_\ */
2023-05-22 08:14:22 +02:00
/* Updated: 2023/05/22 07:37:35 by houtworm ### ########.fr */
2023-05-18 17:02:05 +02:00
/* */
/* ************************************************************************** */
#ifndef PHILO_H
# define PHILO_H
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <fcntl.h>
# include <signal.h>
# include <semaphore.h>
2023-05-22 05:51:23 +02:00
# include <pthread.h>
2023-05-18 17:02:05 +02:00
# 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;
2023-05-22 05:51:23 +02:00
int *alive;
2023-05-18 17:02:05 +02:00
int *target;
sem_t *done;
sem_t *dead;
sem_t *hold;
sem_t *print;
2023-05-22 05:51:23 +02:00
pthread_t thrd;
2023-05-18 17:02:05 +02:00
} 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;
2023-05-22 05:51:23 +02:00
int alive;
2023-05-18 17:02:05 +02:00
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);
2023-05-21 23:43:48 +02:00
int ft_releasetheminds(t_strct *strct, int m);
2023-05-18 17:02:05 +02:00
int ft_cyclecounter(t_strct *strct);
int ft_waitingfordeath(t_strct *strct);
2023-05-22 08:14:22 +02:00
void *ft_alive(void *pointer);
2023-05-18 17:02:05 +02:00
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