blob: 9566136310925db9a59d898d9a0df9e9fd52b505 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* philo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/17 10:23:19 by dkaiser #+# #+# */
/* Updated: 2025/01/18 11:36:45 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHILO_H
# define PHILO_H
# include <unistd.h>
# include <stdlib.h>
# include <stdio.h>
# include <pthread.h>
# include <sys/time.h>
# include "ft_utils.h"
# define ERR_USAGE "Usage: <nbr_of_philos> <ttd> <tte> <tts> [times_must_eat]"
# define ERR_MALLOC "Memory allocation failed"
typedef struct s_fork
{
int available;
pthread_mutex_t mutex;
} t_fork;
typedef struct s_phdata
{
int nbr_of_philos;
int time_to_die;
int time_to_eat;
int time_to_sleep;
int times_must_eat;
int simulation_running;
t_fork *forks;
} t_phdata;
typedef struct s_philo
{
int id;
int times_eaten;
int is_alive;
pthread_t thread;
t_phdata *data;
} t_philo;
int run_simulation(int nbr_of_philos, t_philo *philos);
#endif
|